[mdlug] Python Code Question
teacher1st
teacher1st at bellsouth.net
Sat Sep 5 07:38:25 EDT 2015
Hi Jeremy,
The print statement needs a string as an argument:
print str(int(reply) ** 2)
This will work if reply contains an integer.
Also will work with a float as an input if:
print str(float(reply) ** 2)
I, too, am learning Python, through a free EdX MOOC:
MITx: 6.00.1x Introduction to Computer Science and Programming Using Python
https://www.edx.org/course/introduction-computer-science-mitx-6-00-1x-5
I'm using:
Python 2.7.9
on Ubuntu 15.04
For an editor I'm using the free copy of Canopy:
https://store.enthought.com/
I was in MDLUG a three years ago when I was living in Warren, MI, then
moved to Palm Coast, FL, for a couple years. Now living in Ukraine.
Feel free to correspond about Python. I am 7 hours earlier than
Michigan time.
Best regards,
jim kobe
On 09/05/2015 04:56 AM, JeremyBekka C wrote:
> 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
> _______________________________________________
> mdlug mailing list
> mdlug at mdlug.org
> http://mdlug.org/mailman/listinfo/mdlug
>
More information about the mdlug
mailing list