# Created by Kerrin Tarr
class Question:
def __init__(self, prompt, answer):
self.prompt = prompt
self.answer = answer
question_prompts = [
"Which country's capital is Lisbon?\n(a) Spain\n(b) Portugal\n(c) Germany\n(d) Andorra\n\n",
"\nWhat is the square root of 121?\n(a) 7\n(b) 9\n(c) 11\n(d) 13\n\n",
"\nWho was the UK Prime Minister before Boris Johnson?\n(a) Gordon Brown\n(b) David Cameron\n(c) John Major\n(d) Theresa May\n\n"
]
questions = [
Question(question_prompts [0], "b"),
Question(question_prompts [1], "c"),
Question(question_prompts [2], "d")
]
def run_test(questions):
userInput = 'y'
score = 0
while userInput == 'y':
for i in range(0,len(questions)):
answer = input(question_prompts[i])
print("\nyou chose :"+ answer)
if answer == questions[i].answer:
score+=1
# Uncomment the below set of lines to run program till user input yes.
#userInput = str(input("restart game ? [y / n] : "))
#userInput = userInput.lower()
#print(userInput)
#Comment down below lines if you want your game to keep running (line number : 35 to 40)
if userInput == 'y' :
userInput = 'n'
else:
userInput = str(input())
userInput = userInput.lower()
print("restart game ? [y / n] : " + userInput)
print("You Scored " + str(score) + "/" + str(len(questions)) + " Correct!")
run_test(questions)
إرسال تعليق