-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquiz_game.py
More file actions
78 lines (64 loc) · 2.19 KB
/
quiz_game.py
File metadata and controls
78 lines (64 loc) · 2.19 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
quetions = [
{
'question':"What is the capital of England?",
'options': ["A) Chatragram", "B) Dhaka", "C) Jessore", "D) London"],
'answer': 'D'
},
{
'question':"Which planet is known as red planet?",
'options': ["A) Earth", "B) Mars", "C) Jupitor", "D) Venus"],
'answer': 'B'
},
{
'question':"Who wrote the pay 'Romio & juliot'?",
'options': ["A) William Shakespear", "B) Charles Dickens", "C) Rabindranath Tagore", "D) Kazi Nazrul Islam"],
'answer': 'A'
},
{
'question':"What is longest ocean in Earth?",
'options': ["A) Atlantic", "B) Indian", "C) Arctic", "D) Specific"],
'answer': 'D'
},
{
'question':"What is the chemical symboll of Water?",
'options': ["A) CO2", "B) H2O", "C) O2", "D) Nacl"],
'answer': 'B'
}
]
score = 0
print(f"Welcome to the quiz game!")
print('---------------------\n')
for idx, question in enumerate(quetions,1):
print(f"Q{idx} : {question['question']}")
for option in question['options']:
print(option)
ans = input("Enter your answer (A/B/C/D) ").strip().upper()
if ans == question['answer']:
score += 1
print(f'Correct\n')
else:
print(f"Wrong. the answer is {question['answer']}")
if score == len(quetions):
print(f"Excellent! Perfact score")
elif score >= len(quetions) // 2:
print(f"Good job")
else:
print('Keep Practicing\n')
input('\n Press enter to exit....')
#What it does:
#A list of 5 quiz questions is stored, each with:
#A question text
#Four answer options (A, B, C, D)
#The correct answer key
#The game starts with a welcome message.
#It loops through each question one by one:
#Displays the question and its options.
#Takes the user’s answer input, trims spaces, and converts it to uppercase.
#Compares the answer with the correct one:
#If correct, increases the score and prints "Correct"
#If wrong, shows the correct answer
#After all questions:
#If the user got all right, it says "Excellent! Perfect score"
#If the user got at least half, it says "Good job"
#Otherwise, it says "Keep Practicing"
#Finally, it waits for the user to press enter to exit.