[Q] Question from Python tutorial

Jay O'Connor joconnor at cybermesa.com
Thu Mar 1 14:59:37 EST 2001


Young-Jin Lee wrote:

> I typed them manually. I dind't copy and paste.

OK, then.  It's still a code formatting issue.

If you typed it into something like the command line inertactive environment,
and not IDLE.  There should be some >>> and ... notation

If this is what you have:

>>> x.counter = 1
>>>while x.counter < 10:
...    x.counter = x.counter + 1
...print x.counter


This will raise a syntax error because the interpreter expects that the line
starting with ... is part of the while block and the print statement is not
properly indented, so it raises a syntax error

Based on the formatting in the tutorial, you should just hit enter on that
second line to tell the interpreter that your done with the block.

Your code should look like this instead

>>> x.counter = 1
>>>while x.counter < 10:
...    x.counter = x.counter + 1
...
>>>print x.counter

This will work properly. Note IDLE on Windows (and Linux  for all I
know...never used it) does not use the ... notation, but does use the >>>
notation
--
Jay O'Connor
joconnor at cybermesa.com
http://www.cybermesa.com/~joconnor

Python Language Forum -
http://pub1.ezboard.com/fobjectorienteddevelopmentpython





More information about the Python-list mailing list