Need help for a project I’ve been doing, everything that I’ve coded so far works but I can’t find a solution to what I’ve been looking for. I need an ‘x’ button in the quiz that ends it, shows me my score and sends me back to menu. I’ve been trying but I can’t find anything, would appreciate the help.
Here’s the code:
import random
import operator
def menu():
print("Welcome to the Maths Quiz game. Please choose from the menu below:")
print("-" * 60)
print("[A] New Game")
print("[B] View Today's High Scores")
print("[C] View Past High Scores")
print("[D] Exit")
menu()
option = str(input("What would you like to do?"))
while option != "D":
if option == "A":
#print("New Game")
name = input("What is your name?")
print("Hello " + name.title() + "!")
def quiz():
print('Welcome! This is a 10 question quiz!\n')
score = 0
for i in range(10):
correct = askQuestion()
if correct:
score += 1
print('Correct!')
else:
print('Incorrect!')
print('Your score was {}/10'.format(score))
def askQuestion():
answer = randomCalc()
guess = float(input())
return guess == answer
def randomCalc():
ops = {'+': operator.add,
'-': operator.sub,
'*': operator.mul,
'/': operator.itruediv}
(num1) = random.randint(1, 10)
num2 = random.randint(1, 10)
op = random.choice(list(ops.keys()))
answer = ops.get(op)(num1, num2)
print('What is {} {} {}?'.format(num1, op, num2))
return answer
quiz()
I’ve got the rest figured out but I can’t finish what I wanted with the quiz, it’d be awesome if I could get some help with that, thanks.