0

elif statement

num = input("enter the 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") OUTPUT; enter the number 5 ##press enter Number isn't 5, 11 or 7 Why can anyone help me please

29th Feb 2020, 8:25 AM
Dhinesh Kumar
Dhinesh Kumar - avatar
4 Réponses
+ 5
For the first line... Do it like this num = int(input("enter the number")) You are comparing a string to an int so it will not give the desired output.
29th Feb 2020, 8:27 AM
Utkarsh Sharma
Utkarsh Sharma - avatar
+ 6
Try this. num=int(input("Enter the number ")) Because input gives by the user is always string in the input function whether user input is alphabet or digit.so you need to convert it into an integer.
29th Feb 2020, 8:28 AM
Maninder $ingh
Maninder $ingh - avatar
+ 4
Input is a string. "5" != 5 You would need either convert the input to integer or convert the compared values 5, 11, 7 to strings "5", "11", "7"
29th Feb 2020, 8:27 AM
Seb TheS
Seb TheS - avatar
+ 2
thank you bro its working now
29th Feb 2020, 8:30 AM
Dhinesh Kumar
Dhinesh Kumar - avatar