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()
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
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()
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