+ 5
Why my IDLE doesn't support else, elif ?
I try to work with the else and elif but it only support if condition. I am using python shell 3.7.2 in a windows pc and pydroid3 on andriod.
13 Respostas
+ 2
When you press enter on a blank line the code will be ran in the shell.
You can with few tricks avoid this.
Easy way might be writing:
if condition:
#nothing
And write code before nothing.
+ 2
Sab Thes
Thank You for the trick 😅
+ 2
Rudra That's actually a syntax error, you should not include elif statement in if statement's code block.
This is invalid:
if condition:
elif condition:
pass
+ 1
num = 7
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")
+ 1
Jan Markus I don't think reinstalling is the solution for this problem.
+ 1
Jan Markus
I didn't but i think i have to reinstall it and it may solve the problem
+ 1
Rudra Was the problem that the code starts to run before you reach to write elif and else statements?
+ 1
Sab Thes
When i reach elif and else statements it shows
if 2 ==1:
print('something')
elif 2 == 2:
SyntaxError: invalid syntax
And i can't even write print()
+ 1
Sab thes
Can you show me a code example please
Where i can use else or elif statements?
+ 1
Indentation is necessary in Python, or it won’t compile correctly. Can you delete the whitespace before your elif and try again before pressing Enter after your elif ?
Have you tried to write your code in Notepad for example (with indentation) and copy-paste it in your IDLE and run it ?
+ 1
Sab Thes
When i reach elif and else statements it shows
if 2 ==1:
print('something')
elif 2 == 2:
SyntaxError: invalid syntax
And i can't even write print()
_______________
Its wrong code. You need write this:
if 2 == 1:
print('something')
elif 2 == 2:
print('honey, used four spaces and correct indents')
Put your IDLE to trashbox. Install "PyCharm Comminity Edition". It's good thing. Freeware.