+ 1
How to get input by the user and use the input on control structure in python
How to use the input value entered by the user on if statements. For example : x = input("enter a num") if x = 1: print("one") else: print("false") the above code is correct or wrong. if wrong tell me how to correct it. sorry for my bad english.
4 Answers
+ 3
- The indentation is incorrect at line 1
- input() returns a string (str for short) which you can't compare correctly numbers with so turn that into an int however if the user inputs anything other than a number it will throw an error
- = operator is used for assigning values/objects use == to compare 2 values e.g. 2 == 3, 6 == 6, 9.8 == 9.9
x = int(input("Enter a number: "))
if x == 1:
print("One")
else:
print("False")
+ 3
x = int(input("enter a num"))
if x ==1:
print("one")
else:
print("false")
0
can you please correct it.
0
I think because your asigning x as a string, then you comparing it as a int