+ 1
Why is this not working
number = input() ## if number = 2: print("hi") I do not understand why this gives me a syntax error?
4 ответов
+ 5
1. number = int(input())
2. number == 2
+ 1
Dacleary
input() returns bydefault String value but 2 is numeric so you cannot compare number with string.
To solve this problem just change type of number using int() method like this:
number = int(input())
And also single equal (=) used for assignment. To compare values you need to use double equal (==)
number = int(input())
if number == 2:
print ("Hi")
0
It's not working because it wants better wages.
0
The input function returns string value so you have to convert your variable data from string to integer using int() function and the reason for syntax error is in the if statement at the place of condition you are assigning a new value to your variable which violate the if statement syntax.
Example Code:
num = int(input ("Enter Number "))
if num==2:
print (" Hi ")