+ 1

I am not getting the output

i am getting always the answer 3 I = input (" enter a number") if I==1: print(" number is 1") elif l== 2: print(" number is 2") else: print(" number is 3")

16th Aug 2017, 10:45 AM
Jerryn
Jerryn - avatar
6 Answers
+ 13
The input function prompts the user for input, and returns what they enter as a "string" (with the contents automatically escaped). I = input (" enter a number") if I=="1": print(" number is 1") elif I== "2": print(" number is 2") else: print(" number is 3") # or take the input as an int I = int(input(" enter a number")) if I==1: print(" number is 1") elif I== 2: print(" number is 2") else: print(" number is 3")
16th Aug 2017, 11:51 AM
Dev
Dev - avatar
+ 6
Note that when taking equal comparison int can be compared to float but otherwise different datatyoes return answer as false. input() gets string input
16th Aug 2017, 12:00 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 1
ok thx vry much😀
16th Aug 2017, 11:57 AM
Jerryn
Jerryn - avatar
+ 1
ok thx vry much😀
16th Aug 2017, 11:57 AM
Jerryn
Jerryn - avatar
0
the return type of input() is string. Even if you enter a number it will be considered as string. you can use any one of the following: l=eval(input("enter a number")) l=int(input("enter a number"))
16th Aug 2017, 5:17 PM
Rishi Anand
Rishi Anand - avatar
0
I tried the program using your suggestions and it worked..thx everyone for your inputs
16th Aug 2017, 6:57 PM
Jerryn
Jerryn - avatar