import random def int_check(question, low, high, num_type): while True: error = f'Please enter a number between {low} and {high}.' if num_type == "decimal": data_type = float else: data_type = int try: response = data_type(input(question)) if response >= low and response <= high: return response else: print(error) except ValueError: print(error) rounds_played = 0 rounds_won = 0 rounds_lost = 0 easy_difficulty = ["+", "-"] medium_difficulty = ["x", "÷", "+", "-"] hard_difficulty = ["x", "÷"] rounds = int_check(f"How many rounds do you want? (3 to 10): ", 3, 10, "integer") print(f"Great you chose {rounds} rounds.") print() # asks user for what difficulty they want rounds_difficulty = input("What difficulty do you want? (Easy (e), Medium (m), or Hard (h): ") print(f"You chose {rounds_difficulty} mode") print() while rounds_played < rounds: # picks 'easy', 'medium' or 'hard' based on user input # then chooses what the numbers are and then if its '+', '-', or 'x' # based on the difficulty if rounds_difficulty == "easy": num1 = random.randint(1, 10) num2 = random.randint(1, 10) round_variable = random.choice(easy_difficulty) if round_variable == "-": if num1 > num2: answer = num1 - num2 rounded_num = answer else: answer = num2 - num1 rounded_num = answer else: answer = num1 + num2 rounded_num = answer elif rounds_difficulty == "medium": num1 = random.randint(4, 12) num2 = random.randint(4, 12) round_variable = random.choice(medium_difficulty) if round_variable == "x": answer = num1 * num2 rounded_num = answer elif round_variable == "-": if num1 > num2: answer = num1 - num2 rounded_num = answer else: answer = num2 - num1 rounded_num = answer elif round_variable == "+": answer = num1 + num2 rounded_num = answer else: num1 = random.randint(3, 12) * 2 num2 = random.randint(1, 3) * 2 answer = num1 / num2 rounded_num = round(answer, 2) else: num1 = random.randint(6, 15) num2 = random.randint(6, 15) round_variable = random.choice(hard_difficulty) if round_variable == "x": answer = num1 * num2 rounded_num = answer else: num1 = random.randint(3, 7) * 2 num2 = random.randint(1, 3) * 2 answer = num1 / num2 rounded_num = round(answer, 2) if num1 > num2: print(f"Round {rounds_played + 1} of {rounds} rounds") user_answer = int_check(f"What is {num1} {round_variable} {num2}? ", 0, 500, "decimal") else: print(f"Round {rounds_played + 1} of {rounds} rounds") user_answer = int_check(f"What is {num2} {round_variable} {num1}? ", 0, 500, "decimal") if rounded_num == user_answer: rounds_won += 1 result_display = "✅ Woohoo! Correct answer ✅" print(result_display) print() else: rounds_lost += 1 result_display = f"❌ Incorrect. The correct answer was {rounded_num} ❌" print(result_display) print() rounds_played += 1