+ 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")
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")
+ 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
+ 1
ok thx vry muchđ
+ 1
ok thx vry muchđ
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"))
0
I tried the program using your suggestions and it worked..thx everyone for your inputs