-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathTrivia_quiz.py
More file actions
41 lines (33 loc) · 1.16 KB
/
Trivia_quiz.py
File metadata and controls
41 lines (33 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import random
# Questions and their corresponding answers in a dictionary
questions = {
"What is the capital of France?": "Paris",
"Which planet is known as the Red Planet?": "Mars",
"What is the largest mammal in the world?": "Blue Whale",
"Who painted the Mona Lisa?": "Leonardo da Vinci",
"What is the largest organ in the human body?": "Skin"
}
def get_random_question():
question = random.choice(list(questions.keys()))
answer = questions[question]
return question, answer
def quiz():
score = 0
print("Welcome to the Trivia Quiz Game!")
print("Answer the following questions:")
print("Enter 'quit' at any time to exit the game.")
print()
while True:
question, answer = get_random_question()
print(f"Question: {question}")
user_answer = input("Your answer: ").capitalize()
if user_answer == 'Quit':
break
if user_answer == answer:
score += 1
print("Correct!")
else:
print(f"Sorry, the correct answer is '{answer}'.")
print(f"Thanks for playing! Your total score is: {score}.")
if __name__ == "__main__":
quiz()