import random # checks for an integer more than 0 (allows ) def int_check(question, low_number, high_number): #Checks users enter an integer more than 1 while True: error = f"Please enter a number between {low_number} and {high_number}!" try: response = int(input(question)) #checks that the number is between the low_number and high_number variables if response is low_number <= response <= high_number: print(error) else: return response except ValueError: print(error) # Check that users have entered a valid # option based on a list def string_checker(question, valid_ans): error = f"Please enter a valid option from the following list: {valid_ans}" while True: # Get user 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 user_response == item: 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 user does not enter something that is valid print(error) print() # Displays instructions def instruction(): print(''' **** Instructions **** To begin, choose the number of rounds Then, you'll need to answer the multiplication questions in the quiz correctly Press to end the game at anytime. Good Luck! ''') # Variables yes_no = ["yes", "no"] # Main Routine Starts here print("Multiplication quiz") view_instructions = string_checker("Do you want to see the instructions? ", yes_no) if view_instructions == "yes": instruction() rounds_num = int_check("How many questions would you like to answer? ",2,15) # Game loop starts here for i in range(rounds_num): #A pool of the numbers which the program will generate number1 = random.randint(2, 15) number2 = random.randint(2, 15) answer = number1 * number2 user_answer = int_check(input(f"{number1} x {number2} = ")) if user_answer == answer: print("✅✅✅Correct✅✅✅") elif user_answer != answer: print(f"❌❌❌Incorrect, the answer was {answer}!❌❌❌") #Starts counting how many questions were answered incorrectly for the users score rounds_losses +=1 else: print("Please enter an appropriate answer.") #Statistics Area / Game History #Calculates how much of the quiz was answered correctly and how much was answered incorrectly questions_correct = rounds_num - rounds_losses percent_won = questions_correct / rounds_num * 100 percent_lost = rounds_losses / rounds_num * 100 #The program shows the user their score print("Game Stats") print(f"You answered {questions_correct} question(s) correctly.") print(f"You got {percent_won:.2f}% correct!") print(f"You got {percent_lost:.2f}% incorrect!")