The if and else statement missing int function in program

Question:

I need this code to print out ‘well done’ if the number input by the user is correct. Instead, it just prints out ‘access denied’. The user inputs the answer on the 5th line after the ‘>’. I think it might be something with integers and strings but I’m not sure where I should put the int function.

num1 = random.randint(0, 100)
num2 = random.randint(0, 100)
math_answer = num1 + num2
answer1 = print(num1, "+", num2, "=")
answer1 = input('> ')
if answer1 == math_answer:
    print('Well done')
else:
    print('access denied)
    exit()
Asked By: muckywater

||

Answers:

num1 = random.randint(0, 100)
num2 = random.randint(0, 100)
math_answer = num1 + num2
answer1 = print(num1, "+", num2, "=")
answer1 = int(input('> '))
if answer1 == math_answer:
    print('Well done')
else:
    print('access denied)
    exit()

make sure to add the int()
Error bcs u compare str with int

Answered By: user19419589
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.