Skip to content

Commit d03dc08

Browse files
Add files via upload
1 parent de2936d commit d03dc08

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

Quiz Project/Quiz game.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import random
2+
3+
class QA:
4+
def __init__(self, question, correctAnswer, otherAnswers):
5+
self.question = question
6+
self.corrAnsw = correctAnswer
7+
self.otherAnsw = otherAnswers
8+
9+
qaList = [QA("Where is Minsk?", "in Belarus", ["in Russia", "such a city doesn't exist"]),
10+
QA("What is the capital of Australia?", "Canberra", ["Sydney", "New York", "Australia doesn't exist"]),
11+
QA("Which of the following is not on Earth?", "Sea of Tranquility", ["Mediterranean Sea", "Baltic Sea", "North Sea"]),
12+
QA("Which of the following is not a continent?", "Arctica", ["Antarctica", "America"]),
13+
QA("Which of the following is not an African country?", "Malaysia", ["Madagascar", "Djibouti", "South Africa", "Zimbabwe"])]
14+
15+
corrCount = 0
16+
random.shuffle(qaList)
17+
for qaItem in qaList:
18+
print(qaItem.question)
19+
print("Possible answers are:")
20+
possible = qaItem.otherAnsw + [qaItem.corrAnsw] # square brackets turn correct answer into list for concatenating with other list
21+
random.shuffle(possible)
22+
count = 0 # list indexes start at 0 in python
23+
while count < len(possible):
24+
print(str(count+1) + ": " + possible[count])
25+
count += 1
26+
print("Please enter the number of your answer:")
27+
userAnsw = input()
28+
while not userAnsw.isdigit():
29+
print("That was not a number. Please enter the number of your answer:")
30+
userAnsw = input()
31+
userAnsw = int(userAnsw)
32+
while (userAnsw >= int(len(possible))):
33+
print("That number doesn't correspond to any answer. Please enter the number of your answer:")
34+
userAnsw = int(input())
35+
if possible[userAnsw-1] == qaItem.corrAnsw:
36+
print("Your answer was correct.")
37+
corrCount += 1
38+
else:
39+
print("Your answer was wrong.")
40+
print("Correct answer was: " + qaItem.corrAnsw)
41+
print("")
42+
43+
print("You answered " + str(corrCount) + " of " + str(len(qaList)) + " questions correctly.")

0 commit comments

Comments
 (0)