-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuiz_Game.py
More file actions
60 lines (51 loc) · 1.79 KB
/
Copy pathQuiz_Game.py
File metadata and controls
60 lines (51 loc) · 1.79 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Quiz Game in Python
# Sample questions (you can add more!)
questions = [
{
"question": "What's the capital of France?",
"options": ["Paris", "London", "Berlin", "Madrid"],
"answer": "Paris"
},
{
"question": "Which planet is known as the Red Planet?",
"options": ["Earth", "Mars", "Venus", "Jupiter"],
"answer": "Mars"
},
{
"question": "What's the capital of india?",
"options": ["Delhi", "London", "New delhi", "Madrid"],
"answer": "New delhi"
},
{
"question": "Which famous scientist developed the theory of general relativity?",
"options": ["Isaac Newton", "Albert Einstein", "Stephen Hawking", "Marie Curie"],
"answer": "Albert Einstein"
},
{
"question": "Who wrote the famous play “Romeo and Juliet?",
"options": ["William Wordsworth", "William Shakespeare", "Jane Austen", "Charles Dickens"],
"answer": "William Shakespeare"
},
]
# Initialize score
score = 0
# Quiz loop
for q in questions:
print(q["question"])
for i, option in enumerate(q["options"], start=1):
print(f"{i}. {option}")
user_choice = input("Enter the number corresponding to your answer: ")
if user_choice.isdigit():
user_choice = int(user_choice)
if 1 <= user_choice <= len(q["options"]):
if q["options"][user_choice - 1] == q["answer"]:
print("Correct!\n")
score += 1
else:
print(f"Oops! The correct answer was: {q['answer']}\n")
else:
print("Invalid choice. Try again.\n")
else:
print("Invalid input. Try again.\n")
# Display final score
print(f"Your score: {score}/{len(questions)}")