+ 3

Why else statement not working in python IDLE??

6th May 2017, 7:23 PM
Ayush Kumar Singh
Ayush Kumar Singh - avatar
5 Answers
+ 9
You need almost to unindent the 'else' statement ( he must be aligned with the corresponding 'if' statement ^^ ( look at @Abdul Ghaffar code answer ) So by this way, IDLE would let you type and indent the next line(s) before executing your conditional instructions...
7th May 2017, 12:11 AM
visph
visph - avatar
+ 16
Post your code so we can help u out coz, else statement perfectly works in mine
6th May 2017, 7:29 PM
Ghaffaru Mudashiru
Ghaffaru Mudashiru - avatar
+ 15
You have to pass an argument for the else statement also, eg num =7 if num ==5: print('number is 5') else: print('Number is' + num)
6th May 2017, 7:41 PM
Ghaffaru Mudashiru
Ghaffaru Mudashiru - avatar
+ 2
num=7 if num ==5: print('number is 5 ') else: SyntaxError : invalid syntax
6th May 2017, 7:33 PM
Ayush Kumar Singh
Ayush Kumar Singh - avatar
+ 2
thanks visph it helps me a lot
8th May 2017, 2:36 PM
Ayush Kumar Singh
Ayush Kumar Singh - avatar