[Tutor] need help
Jeff Shannon
jeff at ccvcorp.com
Fri Sep 12 13:10:59 EDT 2003
Hi Valeri,
I'm sending this back to the mailing list as well. It's usually a
good idea to keep discussions like this on the list (you can just hit
'reply all' instead of 'reply' in your mail program to do this), for a
couple of reasons. One is that I might not be available right away --
if, for example, I'd left on vacation just after replying to your
message, you could've been waiting for a long time for a response from
me. On the other hand, if you sent it to the list, you'd have a whole
lot of people who're just as capable of helping you as I am. The
other reason is that somebody else may benefit from seeing the
question and answer -- much of what I know about Python, I've picked
up from following discussions between other people, so I really like
the idea of keeping these discussions where anyone can see them. :)
valeri wrote:
> Hi Jeff!
> Thank you for trying to help.Here is what I enter in my Python IDLE on
> windows xp home edition using livewires 2.0 tutorial pack:
>
>>>if 1 < 2:
>>
> print 'Something is wrong!'
> else:
>
> When I press <enter> after 'else' the 'else' is highlighted in red, and
> there is a "SyntaxError:invalid syntax" message.
The problem here is that the 'else' needs to be at the same
indentation level as the 'if' statement that it matches --
if 1 < 2:
print 'Yes, one *is* less than two.'
else:
print 'Something strange going on here...'
Python uses indentation to determine program structure, and code
that's at the same indentation level is considered to be a single
block. In this case, 'else' should be part of the if statement, and
not part of the block that's only run when the if statement evaluates
to true.
Hope that this helps make sense of the problem. If you have any
further questions or problems, don't hesitate to ask again!
Jeff Shannon
Technician/Programmer
Credit International
More information about the Tutor
mailing list