Invalid syntax error

Ian Kelly ian.g.kelly at gmail.com
Sat Mar 10 12:07:08 EST 2012


On Sat, Mar 10, 2012 at 6:17 AM, Günther Dietrich
<gd.usenet at spamfence.net> wrote:
> In article
> <46758542-1bd6-43fe-8e80-bcf14b7d88d8 at pi6g2000pbc.googlegroups.com>,
>  sl33k <ahsanbagwan at gmail.com> wrote:
>
>>I'm trying project euler problem 3 and I've hit the wall with this
>>error. What could be the problem here?
>>
>> l=[]
>>>>> num=600851475143
>>>>> i=1
>>>>> while i<=num:
>>...     if num%i==0:
>>...         l.append(i)
>>...     i+=1
>>... print max(l)
>>  File "<stdin>", line 5
>>    print max(l)
>>        ^
>>SyntaxError: invalid syntax
>
> You have to insert an empty line after the end of the while loop (before
> the print command), so that the interpreter can run and finish the loop
> before it is to print the result.

Note that this only applies to the interactive interpreter, to help it
identify when to terminate the block and pass on to the compiler.
When running a script, the extra blank lines are unnecessary, and
indentation alone identifies the blocks.



More information about the Python-list mailing list