[Python] generating random math questions [closed]

Discussão em 'Python' iniciado por Stack, Abril 18, 2025.

  1. Stack

    Stack Membro Participativo

    my math contest code should generate random questions and the next question won't appear until you answer the current one correctly , score and time is counted. the problem is that question doesn't change

    import random
    import time

    min_num=1

    max_num=12

    operators=["+","-","/","*"]

    q_num=10

    num1=random.randint(min_num,max_num)

    num2=random.randint(min_num,max_num)

    operate=random.choice(operators)

    exp=str(num1)+" "+operate+ " "+str(num2)

    answers=eval(exp)

    score = 0

    start=time.time()

    for i in range(q_num):

    while True:

    cont = input(f"q#{str(i + 1)}: {exp} = ")

    if cont!=str(answers):

    print("wrong")

    score+=1

    break

    end=time.time()

    total_time=end - start

    print(f"good job(●'◡'●), you got {score} in {round(total_time,1)} seconds")


    screenshot

    Continue reading...

Compartilhe esta Página