import random # check that users have entered a valid # option based on a list def string_checker(question, valid_ans): while True: error = f"Please enter a valid option from the following list: {valid_ans}" # Get the user's response and make sure it's lowercase user_response = input(question).lower() for item in valid_ans: # check if the user response is a word in the list if item == user_response: return item # check if the user response is the same as # the first letter of an item in the list elif user_response == item[0]: return item # print error if the user does not enter something valid print(error) print() def instructions(): """Print instructions""" print(""" *** Instructions *** πŸŽ‰ Let the math fun begin! Step 1: Pick how many rounds you want to play. Step 2: Dive into the game by answering each math question that pops up! 🧠 Rules of the Game: Only type whole numbers β€” no letters, emojis, or other funky symbols allowed. Ready, set, solve! πŸ’₯ """) # check that users have entered a valid def int_check(question): while True: error = "πŸ“πŸ€” Enter a number (1 or greater) to unlock the next question! πŸ€”πŸ“" to_check = input(question) # check for infinite mode if to_check == "": return "infinite" try: response = int(to_check) # checks that the number is greater than / equal to 13 if response < 1: print(error) else: return response except ValueError: print(error) # Main routine Stars here # Initialize game variables mode = "regular" round_played = 0 round_lost = 0 rounds_won = 0 yes_no = ["yes","no"] print(" 𝞹 🧠Multiply Mayhem! 🧠 βœ–") print() # ask the user if they want instructions (check they say yes / no) want_instructions = string_checker("Want to see the instructions first? ", yes_no) # Display the instructions if the user wants to see them... if want_instructions == "yes": instructions() # Ask user for number of rounds / infinite mde num_rounds = int_check("How many rounds would you like?") if num_rounds == "infinite": mode = "infinite" num_rounds = 5 # Game loop starts here while round_played < num_rounds: # Rounds headings if mode == "infinite": rounds_heading = f"\n∞ ∞ ∞ Round {round_played + 1} (SECRET) 5 round Mode ∞ ∞ ∞" else: rounds_heading =f"\nπŸŽ“πŸŒπŸ”Ž Round {round_played + 1} of {num_rounds} πŸ”ŽπŸŒπŸŽ“" print(rounds_heading) # generate a random integer between 0 and 10 random_integer = random.randint(2, 12) random_integer2 = random.randint(2, 12) answer = random_integer * random_integer2 while True: try: user_choice = int(input(f"What is {random_integer} X {random_integer2}? ")) if user_choice == answer: print("πŸ€“βœοΈ Correct! βœοΈπŸ€“") error = 'false' round_played += 1 rounds_won += 1 else: error = 'false' print(f"βœοΈπŸ˜” Incorrect! πŸ˜”βœοΈ correct answer: {answer}.") round_played += 1 round_lost += 1 except ValueError: error = 'true' print("Error! Please enter a valid integer") while error == 'true': try: user_choice = int(input(f"What is {random_integer} X {random_integer2}? ")) if user_choice == answer: print("πŸ€“βœοΈ Correct! βœοΈπŸ€“") error = 'false' round_played += 1 rounds_won += 1 else: error = 'false' print(f"βœοΈπŸ˜” Incorrect! πŸ˜”βœοΈ correct answer: {answer}.") round_played += 1 round_lost += 1 except ValueError: error = 'true' print("Error! Please enter a valid integer") break # Calculate Statistics percent_won = rounds_won / round_played * 100 percent_lost = round_lost / round_played * 100 print('') # Output Game Statistics print("πŸ“ŠπŸ“ˆπŸ’‘ Game Statistics πŸ’‘πŸ“ˆπŸ“Š") print(f"πŸ‘ Won: {percent_won:.2f} \t " f"😒 Lost: {percent_lost:.2f} \t ") print('') print("πŸ“šπŸ‘‹ Thanks for playing! πŸ‘‹πŸ“š")