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 &quot;copyright&quot;, &quot;credits&quot; or &quot;license()&quot; for more information<br><br><br>As for the exact error code....here it is.<br>
<br>&gt;&gt;&gt; <br>while True:<br>    reply = raw_input(&#39;Enter text:&#39;)<br>    if reply == &#39;stop&#39;:<br>        break<br>    elif not reply.isdigit(  ):<br>        print &#39;Bad!&#39; * 8<br>    else:<br>        print int(reply) ** 2<br>
print &#39;bye&#39;<br>SyntaxError: invalid syntax  (note it highlights the print code)... <br><br>This works!!! <br>&gt;&gt;&gt; print&#39;bye&#39;<br>bye<br>&gt;&gt;&gt; <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&#39;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&#39;Aprano <span dir="ltr">&lt;<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>&gt;</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>
&gt; Hi all... I am working from the Learning Python 3rd edition published<br>
&gt; by O&#39;Reily... FYI I am trying to learn Python on my own (not for<br>
&gt; course credit or anything).. I am a psychologist with very limited<br>
&gt; programming experience.. I am anal, and this example code doesn&#39;t<br>
&gt; work.. I am using IDLE to do everything (ni ni ni ni ni)<br>
&gt;<br>
&gt; So here is the code the book give me..<br>
&gt;<br>
&gt; while True:<br>
&gt;     reply = raw_input(&#39;Enter text:&#39;)<br>
&gt;     if reply == &#39;stop&#39;:<br>
&gt;         break<br>
&gt;     elif not reply.isdigit(  ):<br>
&gt;         print &#39;Bad!&#39; * 8<br>
&gt;     else:<br>
&gt;         print int(reply) ** 2<br>
&gt; print &#39;Bye&#39;<br>
&gt;<br>
&gt;<br>
&gt; Idle gives me this error  SyntaxError: invalid syntax (it highlights<br>
&gt; the word print in the print &#39;bye&#39; 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 &quot;from<br>
__future__ import&quot; statement:<br>
<br>
&gt;&gt;&gt; from __future__ import print_function<br>
&gt;&gt;&gt; print &quot;Hello world&quot;<br>
  File &quot;&lt;stdin&gt;&quot;, line 1<br>
    print &quot;Hello world&quot;<br>
                      ^<br>
SyntaxError: invalid syntax<br>
&gt;&gt;&gt; print(&quot;Hello world&quot;)<br>
Hello world<br>
<br>
Alternatively, sometimes if you have an error on one line, the<br>
interpreter doesn&#39;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 &#39;Bye&#39;<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&#39;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>