Today This Free Friday I am working on a project on YouTube a Timed Math challenge
import random
OPERATORS = ["+", "-","*"]
MIN_OPERAND = 3
MAX_OPERAND = 12
def generate_problem():
left = random.randint(MIN_OPERAND, MAX_OPERAND)
right = random.randint(MIN_OPERAND, MAX_OPERAND)
operator = random.choice(OPERATORS)
expr = str(left) + " " + str(right)
answer = evalexpr)
return expr
expr, answer = generate_problem()
- This part of the code does the random choice of a number in the game
for i in range(TOTAL_PROBLEMS):
expr, anwer = generate_problem()
while True:
guess = input("Problem #" + str(i+1) + ": " + expr + " = ")
if guess == str(answer):
break
- This part of the code does the question and makes sure that the answer you put in is correct