Why doesn't this work? (Python) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why doesn't this work? (Python)

a=34+23 print('a is', a) b=23*2 print('b is', b) c=a-b print('c is', c) print('how much is c*(c-b+a)?') correct_answer=(c*(c-b+a)) answer=input('Your answer') print('Your answer:', answer) if answer == correct_answer: print('Correct! Congratulations!') else: print('You are wrong! Try harder!') The 'if' section does not work as intented. After inputting the correct answer, it still thinks it's incorrect. The answer is 242. Thanks for your help!

20th Aug 2018, 8:32 PM
Yaroslav Chastiuk
3 Answers
+ 5
You are comparing string (returned by input() function) with a number (correct_answer). Convert input string into number before assigning it for 'answer' answer = int(input('Your answer'))
20th Aug 2018, 8:39 PM
Ipang
+ 3
You're welcome, glad to help : )
20th Aug 2018, 8:43 PM
Ipang
+ 1
thank you very much!
20th Aug 2018, 8:41 PM
Yaroslav Chastiuk