import random def int_check(question,low, high): """Checks user enters an integer less, or more than or equal to the low and high numbers.""" error = f"Please enter an number between {low} to {high}" while True: try: response = int(input(question)) if response >= low and response <= high: return response else: print(error) except ValueError: print(error) # Check that users have entered a valid # option based on a list # Main routine starts here # Variables rounds_played = 0 rounds_won = 0 game_history = [ ] #start of main program print("This is a multiplication quiz to test your knowledge of the 4 to 9 times tables.") name=input("What is your name? ") num_rounds = int_check(f"{name} how many rounds would you like between 1 to 5? ", 1, 5) print() while rounds_played < num_rounds: print() print(f"Round {rounds_played + 1} of Round {num_rounds}") # Generates a number from 1 to 10 (1 and 10 are both possible) num_2 = random.randint(4, 9) num = random.randint(6,8) correct_answer = num * num_2 while True: user_input = input(f"{num} x {num_2} ") try: # Convert to float to handle both integer and decimal inputs valid_num = int(user_input) break except ValueError: print("Invalid input. Please enter numbers only.") if correct_answer == valid_num: rounds_won += 1 feedback = "Correct" else : feedback = f"Incorrect the correct answer was {correct_answer} " print(feedback) round_feedback = f"{feedback}" history_item = f"Round: {rounds_played +1} - {round_feedback}" game_history.append(history_item) rounds_played +=1 print() print(f" ------- {name}'s Game History -------") print() print(*game_history, sep="\n")