import random # Game Heading - game play starts here print("Multiplication Quiz") print() def int_check(question, low, high): while True: error = f"Please enter an integer that is more than {low} and below {high}" to_check = input(question) try: response = int(to_check) # checks that the number is more than / equal to 1 if low <= response <= high: return response else: print(error) except ValueError: print(error) # 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 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 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 user does not enter something that is valid print(error) print() # Initialise game variables # Compare user answer def compare_ans(user, ans): if user == ans: print("correct") else: print("incorrect") """checks the users response to a question yes / no (y/n) 'yes' or 'no' """ # Main routine def instructions(): """prints instructions""" print(""" **** Instructions **** The program will give you 15 questions, and you will answer all the questions to complete the program. """) # Main routine # Ask the user if they want instructions (check they say yes/no) yes_no = ["yes","no"] want_instructions = string_checker("do you want to see the instructions? ", yes_no) # Display the instructions if the user wants to see them... if want_instructions == "yes": instructions() print() print("program continues") # Main Routine Starts here # adding rounds to code for i in range(15): # Generate random numbers num_1 = random.randint(2, 12) num_2 = random.randint(2, 12) # Generate correct answer correct_answer = num_1 * num_2 user_answer = int_check(f"what is {num_1} x {num_2}? ", 4, 144) # Compare user answer result = compare_ans(user_answer, correct_answer) print("Good job you have completed the questions!!")