Python version<br><br><br>Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32<br>Type "copyright", "credits" or "license()" for more information<br><br><br>As for the exact error code....here it is.<br>
<br>>>> <br>while True:<br> reply = raw_input('Enter text:')<br> if reply == 'stop':<br> break<br> elif not reply.isdigit( ):<br> print 'Bad!' * 8<br> else:<br> print int(reply) ** 2<br>
print 'bye'<br>SyntaxError: invalid syntax (note it highlights the print code)... <br><br>This works!!! <br>>>> print'bye'<br>bye<br>>>> <br><br><br><br>I tried adding parantheses around the print in the code and get the same error<br>
<br><br>It only says SyntaxError:invalid syntax and it highlights the print word.. <br><br> <br><br>According to the book, this print should work, but it doesn't? Any thoughts? Does it work on your computer? <br>
<br><br><br><div class="gmail_quote">On Sun, Apr 4, 2010 at 2:20 AM, Steven D'Aprano <span dir="ltr"><<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im">On Sun, 4 Apr 2010 03:40:57 pm Brian Drwecki wrote:<br>
> Hi all... I am working from the Learning Python 3rd edition published<br>
> by O'Reily... FYI I am trying to learn Python on my own (not for<br>
> course credit or anything).. I am a psychologist with very limited<br>
> programming experience.. I am anal, and this example code doesn't<br>
> work.. I am using IDLE to do everything (ni ni ni ni ni)<br>
><br>
> So here is the code the book give me..<br>
><br>
> while True:<br>
> reply = raw_input('Enter text:')<br>
> if reply == 'stop':<br>
> break<br>
> elif not reply.isdigit( ):<br>
> print 'Bad!' * 8<br>
> else:<br>
> print int(reply) ** 2<br>
> print 'Bye'<br>
><br>
><br>
> Idle gives me this error SyntaxError: invalid syntax (it highlights<br>
> the word print in the print 'bye' line..<br>
<br>
</div>Please do an exact copy and paste of the error and post it, rather than<br>
paraphrasing the error.<br>
<br>
In the meantime, a couple of guesses...<br>
<br>
Are you sure you are using Python 2.6? If you are using 3.1, that would<br>
explain the failure. In Python 3, print stopped being a statement and<br>
became an ordinary function that requires parentheses.<br>
<br>
In Python 2.6, one way to get that behaviour is with the special "from<br>
__future__ import" statement:<br>
<br>
>>> from __future__ import print_function<br>
>>> print "Hello world"<br>
File "<stdin>", line 1<br>
print "Hello world"<br>
^<br>
SyntaxError: invalid syntax<br>
>>> print("Hello world")<br>
Hello world<br>
<br>
Alternatively, sometimes if you have an error on one line, the<br>
interpreter doesn't see it until you get to the next, and then you get<br>
a SyntaxError on one line past the actual error.<br>
<br>
E.g. if you forgot to close the bracket:<br>
<br>
...<br>
<div class="im">else:<br>
print int(reply ** 2<br>
print 'Bye'<br>
<br>
</div>then you would (probably) get a SyntaxError on the line with the print.<br>
<font color="#888888"><br>
<br>
<br>
--<br>
Steven D'Aprano<br>
_______________________________________________<br>
Tutor maillist - <a href="mailto:Tutor@python.org">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
</font></blockquote></div><br>