0

all. Apologies in advance, because I'm sure this is a facepalm-worthy obvious solution. I'm brand new to python and coding in general, and I'm still muddling around. My problem is this: I'm working on a function with nested loops, where three simple addition questions must be answered. The function looks like this:

def themath():
    rounds = 0
    while rounds <= 3:
        num1 = random.randint(10,99)
        num2 = random.randint(10,99)
        sum = num1 + num2
        print(f"{num1} + {num2} = ")
        print(sum)
        answer = input()
        
        while answer != sum:
            print("Incorrect. Please try again.")
            answer = input()
        else:
            rounds = rounds + 1
    else:
        print("Good morning! :)")

My problem is that, no matter what I input, even if its the correct answer to the math problem, I keep getting "Incorrect, please try again," and cannot exit the loop. I apologize again if this is a silly question or I haven't explained it well. Thank you in advance for any input!

0 Answers0