0

elif doesn't work ?

num = input("Enter a number:" ) if num == 5: print("Number is 5") elif num == 11: print("Number is 11") elif num == 7: print("Number is 7") else: print("Number isn't 5, 11 or 7") I think the spaces is the proplem but when i enter any number the result is always else

28th Jan 2019, 4:27 PM
Ragaey M.Ragaa
Ragaey M.Ragaa - avatar
4 Réponses
+ 4
An input is always treated as a string in Python (ver 3.x). And a string cannot equal a number. So you'd have to convert it to int (or float) first. Try this: num = int(input("Enter a number:"))
28th Jan 2019, 4:38 PM
Kishalaya Saha
Kishalaya Saha - avatar
28th Jan 2019, 4:48 PM
Lambda_Driver
Lambda_Driver - avatar
+ 2
You're welcome, Ragaey M.Ragaa! ☺
29th Jan 2019, 4:30 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 1
It works thanks
29th Jan 2019, 3:06 PM
Ragaey M.Ragaa
Ragaey M.Ragaa - avatar