import random def int_check(question, low_number, high_number): while True: error = f"Choose between {low_number} and {high_number}" to_check = input(question) try: response = int(to_check) # checks that the number is more than / equal to 1 if response >= 2 or response <= 15: return response else: print (error) except ValueError: print(error) # store variables rounds_played=0 results_history=[] # Ask the question print("=== Math Quiz ===") num_rounds = int_check("How many rounds would you like between 2 to 15? ",2,15) # Game loop starts here while rounds_played < num_rounds: num1 = random.randint(1, 20) num2 = random.randint(1, 20) # Rounds headings (based on mode) rounds_heading = f"\nπŸ’ΏπŸ’ΏπŸ’Ώ Round {rounds_played + 1} of {num_rounds} πŸ’ΏπŸ’ΏπŸ’Ώ" print(rounds_heading) print() answer = int(input(f"What is {num1} + {num2}? ")) # Check the answer correct = num1 + num2 if answer == correct: correct_message= "βœ… Correct! Well done." print(correct_message) results_history.append(correct_message) else: incorrect_message= f"❌ Incorrect. The correct answer is {correct}." print(incorrect_message) results_history.append(incorrect_message) rounds_played += 1 print("=== Math Quiz results ===") print(results_history)