Question: For my programming assignment I am currently using a templete to mess around with how a trivia game will work. There are a couple things

For my programming assignment I am currently using a templete to mess around with how a trivia game will work. There are a couple things I would like hlelp on so I can use what I learned from this code in my own.

The code

import random

def main(): # Define the categories, questions, and answers for the trivia game. categories = { "Category 1": { "Question 1, ": ["Answer 1", "Answer 2", "Answer 3", "Answer 4"], "Question 2": ["Answer 1", "Answer 2", "Answer 3", "Answer 4"] }, "Video games ": { "Question 1": ["Answer 1", "Answer 2", "Answer 3", "Answer 4"], "Question 2": ["Answer 1", "Answer 2", "Answer 3", "Answer 4"] }, "Category 3":{ "Question 1": ["Answer 1", "Answer 2", "Answer 3", "Answer 4"], "Question 2": ["Answer 1", "Answer 2", "Answer 3", "Answer 4"] }, "Category 4":{ "Question 1": ["Answer 1", "Answer 2", "Answer 3", "Answer 4"], "Question 2": ["Answer 1", "Answer 2", "Answer 3", "Answer 4"] } }

# Run the trivia game by looping through each category and question, displaying the question and answer choices, # and prompting the user for their answer. score = 0 total_questions = 0 for category in categories: print(f" {category}:") for question in categories[category]: total_questions += 1 print(f" {question}") answers = categories[category][question] for i in range(len(answers)): print(f"{i+1}. {answers[i]}") user_answer = input(" Enter your answer (1-4): ") if user_answer.isdigit() and 1 <= int(user_answer) <= 8: if answers[int(user_answer)-1]: print("Correct!") score += 1 else: print("Incorrect.") else: print("Invalid input. Skipped question.")

# Display the user's score as a percentage and give a message based on the percentage. percentage = score / total_questions * 100 if percentage >= 90: message = "Nice job!" else: message = "Needs work." print(f" You scored {score} out of {total_questions} ({percentage:.2f}%). {message}")

if __name__ == "__main__": main()

I am trying to do 3 things before I can move onto my own.

1. I would like to have an exit button present at all times

2. I want to make it so that not every question is answer 1

3. Trying to make it so that I can have different messages for different point ranges. Like between 50 and 70

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!