#a. Title: Multiplication Math Quiz #b. Author: Davi Barbosa #c. Date: 26/05/2026 #d. Version: 2 #e. Purpose: To test the users multiplication skills ##Start screen, Ask question, Get answer, Check answer, update score, increase difficulty, Repeat, Show final percentage, End or restart import random def get_yes_no(question): while True: answer = input(question).lower() if answer in ("yes", "y"): return True elif answer in ("no", "n"): return False else: print("Invalid input. Please enter yes or no.") def play_game(): score = 0 question_count = 1 difficulty = 1 results_list = [] ##Welcome user and get username print('Hello and welcome to the Multiplication Math Quiz.') print('You will answer question on this topic that will get harder as you go') print('Answer your Math questions with numbers!') username = input('What name would you like to be called by? ') print(f'Good luck, {username}!') while question_count < 11: ##Generates the each number in the question for each difficulty level if difficulty == 1: num1 = random.randint(1,10) num2 = random.randint(1,10) elif difficulty == 2: num1 = random.randint(5,10) num2 = random.randint(11,15) else: num1 = random.randint(11,20) num2 = random.randint(10,15) ##Ask the math question while True: try: user_answer = int(input(f'{question_count} What is {num1} x {num2}? ')) if user_answer < 1 or user_answer > 400: print('Please enter a number between 1 and 400.') else: break except ValueError: print('Please enter a whole number') ##Check answer correct_answer = num1 * num2 if correct_answer == user_answer: result = 'Correct!' print(result) score += 1 else: result = 'Incorrect!' print(f'{result} The correct answer is {correct_answer}') results_list.append(f'{question_count} {result}') question_count += 1 ##Set difficulty for certain scores if score <= 3: difficulty = 1 elif score <= 6: difficulty = 2 else: difficulty = 3 ##Show score and difficulty print(f'Score = {score} / {question_count}') print(f'Current difficulty: {difficulty}') print() ##Final percentage percentage = (score / 10) * 100 print(f'Final percentage = {percentage}%!') # return username #Ask if the user wants to see their history if get_yes_no("Do you want to see your quiz results? (yes/no) "): print(*results_list, sep="\n") ##Restart loop while True: username = play_game() if get_yes_no("Nice work, would you like to play again? (yes/no) "): continue else: print(f"Thanks for playing {username}") break