# Need an exit button for my project

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
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")

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):
if correct:
score += 1
print('Correct!')
else:
print('Incorrect!')

guess = float(input())

def randomCalc():
'-': operator.sub,
'*': operator.mul,
'/': operator.itruediv}
(num1) = random.randint(1, 10)
num2 = random.randint(1, 10)
op = random.choice(list(ops.keys()))
print('What is {} {} {}?'.format(num1, op, num2))

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.

Hi.

Does this do what you have in mind?

``````import random
import operator

'A': "New Game",
'B': "View Today's High Scores",
'C': "View Past High Scores",
'D': "Exit"
}
print()

def start():
name = input("What is your name? ")
print("Hello " + name.title() + "!")
quiz()

def quiz():
print('Welcome! This is a 10 question quiz!\n')
score = 0
for i in range(10):
if correct == "X":
break
elif correct:
score += 1
print('Correct!')
else:
print('Incorrect!')

guess = input().upper()
if guess == "X":
return guess
else:
try:
guess = float(guess)
except ValueError:
return

def randomCalc():
'-': operator.sub,
'*': operator.mul,
'/': operator.itruediv}
(num1) = random.randint(1, 10)
num2 = random.randint(1, 10)
op = random.choice(list(ops.keys()))
print('What is {} {} {}?'.format(num1, op, num2))

print("Welcome to the Maths Quiz game. Please choose from the menu below:")
while True:
print()
option = input("What would you like to do? ").upper()
print()

if option not in options:
print()
elif option == "A":
start()
elif option == "B":
pass  # to do
elif option == "C":
pass  # to do
elif option == "D":
print("Thank you and have a good day!")
break
``````

I could not resist correcting one or two mistakes for you and improving on the logic flow, but that aside, it’s still all your own work.

If you have any questions, feel free to ask.

Btw: I don’t think that I’ve introduced any bugs, but if I have and you can’t squish them, lmk.

1 Like

Yes, thank you so much, this does exactly what I thought of! I’m still a beginner so thanks a lot for helping me and adjusting my code ! 1 Like

You’re welcome.

For a beginner, you’ve done a very good job. Keep at it and happy coding.

1 Like