Need help with programming.

Joseph Wilhelm jwilhelm at outsourcefinancial.com
Thu Oct 25 02:02:46 CEST 2001


> Hello. I've just begun using Python, and am now getting into
> simple commands.
> Everytime I try to use  "else:" I get this message:
>
> SyntaxError: invalid syntax
> >>>
>
> I've tried retyping it, skipping it, etc. but it's really
> bothering me... is
> there an alternative I can use for "else:" such as "or:"...
> Or am I typing it
> wrong, or something? I tried browsing a few webpage's a bit,
> to hopefully find
> an answer to my question, but I didnt find anything to help
> me out. Any help
> would be very much appreciated. Thank you.
>


Well, my suggestion on this would be to check your indentation level. Keep
in mind that the "else:" line needs to be at the same indentation level as
the "if ...:" line.  So for instance, your code should look like this:

if something_is_true:
	do_stuff()
else:
	do_nothing()

Whereas, if you have this:

if something_is_true:
	do_stuff()
	else:
		do_nothing()

That will just break, and probably give the error you're saying.
Hope that helps.

--Joseph Wilhelm





More information about the Python-list mailing list