[Python] elif & else

Started by
5 comments, last by daviangel 16 years, 3 months ago
Everytime I type them it says Invalid Syntax... Help?
Advertisement
Show an example of code that gives that problem. Make sure to use [code] or [source] tags to ensure that the spacing shows up properly.
Did you put colons after them?

ie

if blah:    do_stuff()elif that:    do_other_stuff()else:    do_nothing()
Eric Richards
>>> if 9 == 9:	do_stuff()	elif that:		SyntaxError: invalid syntax


Elif is higlighted.
Quote:Original post by X Jado X
>>> if 9 == 9:	do_stuff()	elif that:		SyntaxError: invalid syntax


Elif is higlighted.


The "elif" needs to be indented to the same level as the "if".
Ahh I see, thank you.
Quote:Original post by bakery2k1
Quote:Original post by X Jado X
>>> if 9 == 9:	do_stuff()	elif that:		SyntaxError: invalid syntax


Elif is higlighted.


The "elif" needs to be indented to the same level as the "if".

Yeah that's one of the things that first aggravated me when I first learned Python never mind not using elseif like 99% of the other languages!
Since whitespace matters also unlike 99% of other languages a good Python editor is essential since I used the one that came with Python and it never alerted me to silly mistakes like this.

[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe

This topic is closed to new replies.

Advertisement