import random # function go here def welcome(): """Welcome the user and ask for a name""" while True: print("hello and welcome to the math quiz") user_name = input("What is your name? ") print(f"Hi {user_name} lets start the quiz!") break def yes_no(question): """checks user response to a question is yes / no""" while True: response = input(question).lower() # check the user says yes / no if response == "yes" or response == "Yes": return "yes" elif response == "no" or response == "No": return "no" else: print("please enter yes or no") def instructions(): """Prints instructions""" print(""" *** Instructions **** Answer the following questions and get your final score at the end """) def int_check(question, low_number, high_number): """Checks users enter an integer more than / equal to 13""" error = f"Please enter a number between {low_number} and {high_number}." while True: try: response = int(input(question)) if response < low_number or response > high_number: print(error) else: return response except ValueError: print(error) # Main routine # ask the user if they want instructions (check they say yes / no) quiz_history=[] welcome() want_instructions = yes_no("Do you want the see the instructions? ") # Display the instructions if the user wants to see them... if want_instructions == "yes": instructions() print() rounds = int_check("How many rounds do you want between 1 - 10 ", 1, 10) print(f"There are {rounds} rounds.... lets begin") for i in range(rounds): num_1 = random.randrange(1,10) num_2 = random.randrange(1,10) answer = num_1 * num_2 user_answer =int(input(f"What is {num_1} x {num_2}? ")) if user_answer == answer: print("correct!") quiz_history.append("correct") else: print(f"incorrect, the answer was {answer} try again") quiz_history.append("incorrect") print() print("Results") print(*quiz_history, sep="\n")