-
Notifications
You must be signed in to change notification settings - Fork 0
/
thegameshow.py
43 lines (39 loc) · 1.83 KB
/
thegameshow.py
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
import random
class QA:
def __init__(self, question, correctAnswer, otherAnswers):
self.question = question
self.corrAnsw = correctAnswer
self.otherAnsw = otherAnswers
qaList = [QA("Where is the Philipines?", "Asia", ["Africa", "North America"]),
QA("What is the capital of Australia?", "Canberra", ["Sydney", "New York", "Australia doesn't exist"]),
QA("Which of the following is not on Earth?", "Sea of Tranquility", ["Mediterranean Sea", "Baltic Sea", "North Sea"]),
QA("Which of the following is not a continent?", "Arctica", ["Antarctica", "America"]),
QA("Which of the following is not an African country?", "Malaysia", ["Madagascar", "Djibouti", "South Africa", "Zimbabwe"])]
corrCount = 0
random.shuffle(qaList)
for qaItem in qaList:
print(qaItem.question)
print("Possible answers are:")
possible = qaItem.otherAnsw + [qaItem.corrAnsw] # square brackets turn correct answer into list for concatenating with other list
random.shuffle(possible)
count = 0 # list indexes start at 0 in python
while count < len(possible):
print(str(count+1) + ": " + possible[count])
count += 1
print("Please enter the number of your answer:")
userAnsw = input()
while not userAnsw.isdigit():
print("That was not a number. Please enter the number of your answer:")
userAnsw = input()
userAnsw = int(userAnsw)
while not (userAnsw > 0 and userAnsw <= len(possible)):
print("That number doesn't correspond to any answer. Please enter the number of your answer:")
userAnsw = input()
if possible[userAnsw-1] == qaItem.corrAnsw:
print("Your answer was correct.")
corrCount += 1
else:
print("Your answer was wrong.")
print("Correct answer was: " + qaItem.corrAnsw)
print("")
print("You answered " + str(corrCount) + " of " + str(len(qaList)) + " questions correctly.")