# Untitled

unknown

plain_text

a month ago

1.2 kB

0

Indexable

Never

^{}

import random def generate_hidden_equation(): # Generates a random mathematical equation a = random.randint(1, 9) b = random.randint(1, 9) operator = random.choice(['+', '-', '*']) equation = f'{a} {operator} {b}' result = eval(equation) return equation, result def display_hidden_equation(equation): # Displays the mathematical equation with asterisks hiding the result return f'Guess the result of the equation: {equation} = ****' def guess_hidden_result(result): # Allows the user to guess the result of the equation guess = input("Enter your guess for the result: ") if guess == str(result): return True else: print("Incorrect guess. Try again.") return False def main(): # Main function to run the game equation, result = generate_hidden_equation() equation_display = display_hidden_equation(equation) print("Welcome to the Hidden Equation Game!") print(f"{equation_display}") while not guess_hidden_result(result): pass # Keep prompting until the correct guess is made print("Congratulations! You guessed the result of the equation.") if __name__ == "__main__": main()

Leave a Comment