import random # function go here def yes_no(question): """Checks user response to a question is yes / no (y/n), return 'yes' or 'no'""" while True: response = input(question).lower() # check the user says yes / no / y / n if response == "yes" or response == "y": return "yes" elif response == "no" or response == "n": return "no" else: print("please enter yes / no") def instructions(): """Prints instructions""" print(""" *** Instructions *** Pick between 1-10 rounds of multiplication, answer the questions see how many you can get correct! """) def int_check(question, low_number, high_number): """Checks user enters a number between the low and high number""" 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 # variables rounds_played = 0 result = [] # ask the user if they want instructions (check they say yes / no) want_instructions = yes_no("Do you want to 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 to play? ", 1, 10) print(f"You are playing {rounds} rounds") while rounds_played < rounds: number_1 = random.randrange(1, 10) number_2 = random.randrange(1, 10) correct_answer = number_1 * number_2 user_answer = int_check(f"what is {number_1} x {number_2}? ", 1, 100) if correct_answer == (user_answer): print("Correct!") result.append("Correct") else: print(f"Incorrect!, The correct answer was {correct_answer}") result.append("Incorrect") rounds_played += 1 print(result) print("The program has ended.")