import random
import os
from rich import print
from rich.panel import Panel
from time import sleep
D = 0 # Level tracker
ATTEMPTS = 3 # Number of attempts per question
# Function to clear the console (works on Windows and UNIX-based systems)
def clear_console():
os.system('cls' if os.name == 'nt' else 'clear')
# Function to generate a random math question
def generate_question(level):
# Generate two random numbers with difficulty scaling
num1 = random.randint(1, 10 + level * 10)
num2 = random.randint(1, 10 + level * 10)
# Randomly select an operation
operation = random.choice(['+', '-', '*', '/'])
# Calculate the correct answer
if operation == '+':
answer = num1 + num2
elif operation == '-':
answer = num1 - num2
elif operation == '*':
answer = num1 * num2
elif operation == '/':
answer = round(num1 / num2, 2) # Round division result to 2 decimals
question = f"{num1} {operation} {num2}"
return question, answer
# Function to display a level-up message
def level_up_message(level):
print(Panel(f"[green bold]๐ CONGRATULATIONS! LEVEL {level} COMPLETED! ๐", style="bold green"))
# Main game function
def math_game():
global D
clear_console()
print(Panel("[bold blue]๐ฏ WELCOME TO MATH TEST BY MR AYUSH ๐ฏ", style="bold blue"))
sleep(2)
try:
while True:
# Generate a new question
question, correct_answer = generate_question(D)
# Display the question
print(Panel(f"""
[green]LEVEL: {D}
[blue]Solve the following:
[red]{question} = ?
[green](You have {ATTEMPTS} attempts. Type 'quit' to exit.)
"""))
# Allow multiple attempts for the question
attempts_left = ATTEMPTS
while attempts_left > 0:
user_input = input("Enter your answer: ").strip()
# Check if the user wants to quit
if user_input.lower() == 'quit':
print("[bold red]Goodbye! Thanks for playing! ๐")
return
# Validate user input
try:
user_answer = float(user_input)
except ValueError:
print("[bold red]Invalid input! Please enter a number.")
continue
# Check the answer
if user_answer == correct_answer:
print("[bold green]โ Correct Answer! Well done! ๐")
sleep(2)
D += 1
level_up_message(D)
clear_console()
break
else:
attempts_left -= 1
print(f"[bold yellow]โ Wrong answer! Try again. Attempts left: {attempts_left}")
# If no attempts left, show the correct answer and exit
if attempts_left == 0:
print(f"[bold red]๐ข Out of attempts! The correct answer was: {correct_answer}")
print("[bold red]Better luck next time! ๐")
break
except Exception as e:
print(f"[bold red]An error occurred: {e}")
# Run the game
if __name__ == "__main__":
math_game()
RUN IN PYDRIOD 3
FULL CREDIT:- @ll_toxic_ayush_ll
MUST GIVE CREDIT [ else you and your family is gay ]
import os
from rich import print
from rich.panel import Panel
from time import sleep
D = 0 # Level tracker
ATTEMPTS = 3 # Number of attempts per question
# Function to clear the console (works on Windows and UNIX-based systems)
def clear_console():
os.system('cls' if os.name == 'nt' else 'clear')
# Function to generate a random math question
def generate_question(level):
# Generate two random numbers with difficulty scaling
num1 = random.randint(1, 10 + level * 10)
num2 = random.randint(1, 10 + level * 10)
# Randomly select an operation
operation = random.choice(['+', '-', '*', '/'])
# Calculate the correct answer
if operation == '+':
answer = num1 + num2
elif operation == '-':
answer = num1 - num2
elif operation == '*':
answer = num1 * num2
elif operation == '/':
answer = round(num1 / num2, 2) # Round division result to 2 decimals
question = f"{num1} {operation} {num2}"
return question, answer
# Function to display a level-up message
def level_up_message(level):
print(Panel(f"[green bold]๐ CONGRATULATIONS! LEVEL {level} COMPLETED! ๐", style="bold green"))
# Main game function
def math_game():
global D
clear_console()
print(Panel("[bold blue]๐ฏ WELCOME TO MATH TEST BY MR AYUSH ๐ฏ", style="bold blue"))
sleep(2)
try:
while True:
# Generate a new question
question, correct_answer = generate_question(D)
# Display the question
print(Panel(f"""
[green]LEVEL: {D}
[blue]Solve the following:
[red]{question} = ?
[green](You have {ATTEMPTS} attempts. Type 'quit' to exit.)
"""))
# Allow multiple attempts for the question
attempts_left = ATTEMPTS
while attempts_left > 0:
user_input = input("Enter your answer: ").strip()
# Check if the user wants to quit
if user_input.lower() == 'quit':
print("[bold red]Goodbye! Thanks for playing! ๐")
return
# Validate user input
try:
user_answer = float(user_input)
except ValueError:
print("[bold red]Invalid input! Please enter a number.")
continue
# Check the answer
if user_answer == correct_answer:
print("[bold green]โ Correct Answer! Well done! ๐")
sleep(2)
D += 1
level_up_message(D)
clear_console()
break
else:
attempts_left -= 1
print(f"[bold yellow]โ Wrong answer! Try again. Attempts left: {attempts_left}")
# If no attempts left, show the correct answer and exit
if attempts_left == 0:
print(f"[bold red]๐ข Out of attempts! The correct answer was: {correct_answer}")
print("[bold red]Better luck next time! ๐")
break
except Exception as e:
print(f"[bold red]An error occurred: {e}")
# Run the game
if __name__ == "__main__":
math_game()
RUN IN PYDRIOD 3
FULL CREDIT:- @ll_toxic_ayush_ll
MUST GIVE CREDIT [ else you and your family is gay ]