import random score = 0 for question_num in range(1, 11): print(f"\n--- Question {question_num} of 10 ---") random_1 = random.randint(1, 15) random_2 = random.randint(1, 15) ans = random_1 * random_2 print(f"What is {random_1} x {random_2} =") user_input = input("Enter your answer: ") try: user_ans = int(user_input) if user_ans == ans: print("You got it!") score += 1 else: print(f"The correct answer was {ans}.") except ValueError: print(f"That was not a valid number.") print("==========") print("Quiz Finished") print(f"Your final score was {score}/10") print("==========") def string_checker(question, valid_ans=("yes", "no")): error = f"Please enter a valid option from the following list: {valid_ans}" while True: user_response = input(question).lower() for item in valid_ans: if item == user_response: return item elif user_response == item[0]: return item print(error) print() # Displays instructions def instructions(): print(""" **** Instructions **** To begin, choose the number of rounds (or press for infinite mode). Then play against the computer. You need to answer the math question that you get assigned. Press to end the game at anytime. Good luck! """) # checks for an integer more than 0 (allows ) def int_check(question): while True: error = "Please enter a valid integer that is 1 or more." to_check = input(question) # check for infinite mode if to_check =="": return "infinite" try: response = int(to_check) # checks that the number is more than / equal to 1 if response < 1: print(error) else: return response except ValueError: print(error)