[mdlug] Python Code Question

JeremyBekka C jrchristophel at gmail.com
Fri Sep 4 21:56:48 EDT 2015


Hello,

I am trying to learn Python by working through the book "Learning Python
(3th Edition) - Ascher, Lutz (O'Reilly, 2008)". I have a question regarding
one of the examples in the book which is using python 2.2. The code is the
following:

while True:
    reply = raw_input('Enter text:')
    if reply == 'stop' : break
    print int(reply) ** 2
print 'Bye

When I run this in the Idle interpreter it gives me an error on line 4 with
the int() built-in and says "SyntaxError: invalid syntax".

If I run this in the terminal I get the following:

>>> while True:
...       reply = raw_input('Enter text:')
...       if reply == 'stop' : break
...       print int(reply) ** 2
...    print 'Bye'
  File "<stdin>", line 5
    print 'Bye'
        ^
SyntaxError: invalid syntax

Any idea what is wrong here? Iooked up the integer built-in on the python
website and it did not give me any ideas what is wrong.

Thanks


More information about the mdlug mailing list