-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquiz_game.py
More file actions
81 lines (73 loc) · 2.14 KB
/
quiz_game.py
File metadata and controls
81 lines (73 loc) · 2.14 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
79
80
81
#quiz game in python program
#create a dictionary that stores questions and answers
#have a variable that tracks the score of the player
#loop through the dictionary using the key value pairs
#display each question to the user and allow them to answers
#tell them if they are right or wrong
#show user the final result when quiz is completed
print("Welcome to the quiz!")
playing = input("Do you want to play? ")
if playing != "yes":
quit()
print ("Okay! Let's play :)")
print ("")
quiz = {
"question1": {
"question": "What is the capital of India?",
"answer": "New Delhi"
},
"question2": {
"question": "What is the capital of Philippines?",
"answer": "Manila"
},
"question3": {
"question": "What is the capital of Germany?",
"answer": "Berlin"
},
"question4": {
"question": "What is the capital of Japan?",
"answer": "Tokyo"
},
"question5": {
"question": "What is the capital of Kenya?",
"answer": "Nairobi"
},
"question6": {
"question": "What is the capital of Norway?",
"answer": "Oslo"
},
"question7": {
"question": "What is the capital of Portugal?",
"answer": "Lisbon"
},
"question8": {
"question": "What is the capital of Sweden?",
"answer": "Stockholm"
},
"question9": {
"question": "What is the capital of Colombia?",
"answer": "Bogota"
},
"question10": {
"question": "What is the capital of Finland?",
"answer": "Helsinki"
}
}
score = 0
for key, value in quiz.items():
print(value['question'])
answer = input ('Answer? ')
if answer.lower() == value['answer'].lower():
print ('Correct!')
score = score + 1
print ('Your score is ' + str(score))
print ("")
print ("")
else:
print('Wrong!')
print ('The answer is : ' + value['answer'])
print ('Your score is ' + str(score))
print("")
print("")
print ("You got " + str(score) + " out of 10 questions correctly!")
print ("Your percentage is " +str(int(score/10*100)) + "%")