-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPython Quiz Game.py
More file actions
82 lines (65 loc) · 2.68 KB
/
Copy pathPython Quiz Game.py
File metadata and controls
82 lines (65 loc) · 2.68 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
82
def quiz_game():
guesses = []
correct_guesses = 0
question_num = 1
for keys in questions:
print("------------------------------------------")
print(keys)
for i in options[question_num-1]:
print(i)
guess = input("Enter A, B, C or D: ").upper()
guesses.append(guess)
correct_guesses += check_answer(questions.get(keys), guess)
question_num += 1
display_score(correct_guesses, guesses)
def check_answer(answer, guess):
if answer == guess:
print("Correct!")
return 1
else:
print("Wrong!")
return 0
def display_score(correct_guesses, guesses):
print("------------------------------------------")
print("Result")
print("------------------------------------------")
print("Answer: ", end="")
for i in questions:
print(questions.get(i), end=" ")
print()
print("Guesses: ", end="")
for i in guesses:
print(i, end=" ")
print()
score = int((correct_guesses/len(questions))*100)
print("Your score is " + str(score) + "%")
def play_again():
response = input("Do you want to play again?(y/n): ").lower()
if response == "y":
return True
else:
return False
questions = {"What is the largest lake in the world?": "B",
"Which planet in the solar system is known as the “Red Planet”?": "C",
"Who wrote the novel “War and Peace”?": "C",
"What is the capital of Japan?": "B",
"Which river is the longest in the world?": "C",
"What gas is used to extinguish fires?": "B",
"What animal is the national symbol of Australia?": "A",
"Which of the following planets is not a gas giant?": "A",
"What is the name of the process by which plants convert sunlight into energy?": "B",
"What chemical element is designated as “Hg”?": "D"}
options = [["A. Caspian Sea", "B. Baikal", "C. Lake Superior", "D. Ontario"],
["A. Venus", "B. Earth", "C. Mars", "D. Jupiter"],
["A. Anton Chekhov", "B. Fyodor Dostoevsky", "C. Leo Tolstoy", "D. Ivan Turgenev"],
["A. Beijing", "B. Tokyo", "C. Seoul", "D. Bangkok"],
["A. Amazon", "B. Mississippi", "C. Nile", "D. Yangtze"],
["A. Oxygen", "B. Nitrogen", "C. Helium", "D. Hydrogen"],
["A. Kangaroo", "B. Koala", "C. Emu", "D. Crocodile"],
["A. Mars", "B. Jupiter", "C. Saturn", "D. Uranus"],
["A. Respiration", "B. Photosynthesis", "C. Oxidation", "D. Evolution"],
["A. Silver", "B. Tin", "C. Copper", "D. Mercury"]]
quiz_game()
while play_again():
quiz_game()
print("Bye!")