Skip to main content
GameDev.net gamedev.net
🔒 Locked

[Python] elif & else

Started by X Jado X Jan 31, 2008 at 8:47 PM 5 replies 1.4k views
Original Post
X Jado X
X Jado X
Everytime I type them it says Invalid Syntax... Help?
SiCrane
SiCrane
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.
Megaman_22
Megaman_22
Did you put colons after them?

ie

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


Elif is higlighted.
bakery2k1
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".
X Jado X
X Jado X
Ahh I see, thank you.
daviangel
daviangel
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.