Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help! I need to modify the below trivia challenge game to give different

ID: 3533287 • Letter: P

Question

Please help! I need to modify the below trivia challenge game to give different point values to different questions, keep total ofcorrect score points, and keep track of last high score. Please please help and don't just put random stuff for points. Thanks!!


# Trivia Challenge
# Trivia game that reads a plain text file

import sys

def open_file(file_name, mode):
    """Open a file."""
    try:
        the_file = open(file_name, mode)
    except IOError as e:
        print("Unable to open the file", file_name, "Ending program. ", e)
        input(" Press the enter key to exit.")
        sys.exit()
    else:
        return the_file

def next_line(the_file):
    """Return next line from the trivia file, formatted."""
    line = the_file.readline()
    line = line.replace("/", " ")
    return line

def next_block(the_file):
    """Return the next block of data from the trivia file."""
    category = next_line(the_file)
   
    question = next_line(the_file)
   
    answers = []
    for i in range(4):
        answers.append(next_line(the_file))
       
    correct = next_line(the_file)
    if correct:
        correct = correct[0]
       
    explanation = next_line(the_file)

    return category, question, answers, correct, explanation

def welcome(title):
    """Welcome the player and get his/her name."""
    print(" Welcome to Trivia Challenge! ")
    print(" ", title, " ")

def main():
    trivia_file = open_file("trivia.txt", "r")
    title = next_line(trivia_file)
    welcome(title)
    score = 0

    # get first block
    category, question, answers, correct, explanation = next_block(trivia_file)
    while category:
        # ask a question
        print(category)
        print(question)
        for i in range(4):
            print(" ", i + 1, "-", answers[i])

        # get answer
        answer = input("What's your answer?: ")

        # check answer
        if answer == correct:
            print(" Right!", end=" ")
            score += 1
        else:
            print(" Wrong.", end=" ")
        print(explanation)
        print("Score:", score, " ")

        # get next block
        category, question, answers, correct, explanation = next_block(trivia_file)

    trivia_file.close()

    print("That was the last question!")
    print("You're final score is", score)

main()
input(" Press the enter key to exit.")

Explanation / Answer

# modifications you must do

# add a line in the input file to store custom points for each question

# i have commented weher i have used these values# for last High Score you need to write to some file

#comment on this answer and ask if you need any more help


# Trivia Challenge

# Trivia game that reads a plain text file


import sys


def open_file(file_name, mode):

"""Open a file."""

try:

the_file = open(file_name, mode)

except IOError as e:

print("Unable to open the file", file_name, "Ending program. ", e)

input(" Press the enter key to exit.")

sys.exit()

else:

return the_file


def next_line(the_file):

"""Return next line from the trivia file, formatted."""

line = the_file.readline()

line = line.replace("/", " ")

return line


def next_block(the_file):

"""Return the next block of data from the trivia file."""

category = next_line(the_file)

question = next_line(the_file)

answers = []

for i in range(4):

answers.append(next_line(the_file))

correct = next_line(the_file)

if correct:

correct = correct[0]

explanation = next_line(the_file)

# add a line in the input file to store custom points for a question

# now get those points

answerScore = next_line(the_file)


return category, question, answers, correct, explanation, answerScore


def welcome(title):

"""Welcome the player and get his/her name."""

print(" Welcome to Trivia Challenge! ")

print(" ", title, " ")

def main():

trivia_file = open_file("trivia.txt", "r")

title = next_line(trivia_file)

welcome(title)

score = 0

#get lastHighScore from some input file else initialize here

lastHighScore = 0

  


# get first block

#get answerScore for block , to have different points for different questions

category, question, answers, correct, explanation ,answerScore= next_block(trivia_file)

while category:

# ask a question

print(category)

print(question)

for i in range(4):

print(" ", i + 1, "-", answers[i])


# get answer

answer = input("What's your answer?: ")


# check answer

if answer == correct:

print(" Right!", end=" ")

#add the custom points for the question

score += answerScore

else:

print(" Wrong.", end=" ")

print(explanation)

print("Score:", score, " ")


# get next block

category, question, answers, correct, explanation, answerScore = next_block(trivia_file)


trivia_file.close()

#storing lastHighScore

if score > lastHighScore :

lastHighScore = score

#write this lastHighScore value to some file to make sure that it can be read later


print("That was the last question!")

print("You're final score is", score)

main()

input(" Press the enter key to exit.")