+ 2
else statement
num = input() if num == 5: print("Number is 5") else: if num == 11: print("Number is 11") else: if num == 7: print("Number is 7") else: print("Number isn't 5, 11 or 7") What is wrong in this ?
5 Answers
+ 14
@Dayve There is... Python takes the user input and turns into a string... He will need to change num to integer... num = int(num)
+ 8
Nothing wrong with it! It's working correct in CP.
BTW you can use elif instead of else if.
+ 5
The 'if num==5' statement will check if the variable num is equal to the number 5 (integer). And of course it never will, because you assigned a string to it (input by default acquires a string type).
What you need to do is to change the first line to:
num = int(input())
That shall do the trick ;)
0
But when I am giving any input its showing last satatement every time . Pls check once
0
remove else: from all except last one