+ 2
Why does it not work?
Input (âfive plus five is:â) If input == ten: Print (âCorrect!â) Why does it not work in Python? Thanks!
2 Answers
+ 3
You have to storage the input() value in a variable, then you have to call that variable
a = input("five plus five is:")
if a == "ten":
print("Correct!")
+ 9
Here are a few points:
1. Python is case sensitive and doesn't recognize 'Input'. Always use 'input'.
2. Same with 'Print'. Always use 'print'. Also 'If'. Always use 'if'.
3. The result of input() is always a string and can only be compared with another string, so you should compare it with "ten" as @Sebastian said, not ten.
4. input() is a function, but input is just a word - always use input with parentheses, i.e. input().
5. You can either store the string value of the user's input (if you plan to use it again) in a variable as @Sebastian suggested, or, if it's going to be a one time use, you can shorten your code to:
if input("five plus five is:") == "ten":
print("Correct!")