Invalid syntax error

S

sl33k

I'm trying project euler problem 3 and I've hit the wall with this
error. What could be the problem here?

l=[].... if num%i==0:
.... l.append(i)
.... i+=1
.... print max(l)
File "<stdin>", line 5
print max(l)
^
SyntaxError: invalid syntax
 
A

Andrew Berg

I'm trying project euler problem 3 and I've hit the wall with this
error. What could be the problem here?

l=[]... if num%i==0:
... l.append(i)
... i+=1
... print max(l)
File "<stdin>", line 5
print max(l)
^
SyntaxError: invalid syntax
You must be using Python 3. Along with many, many other changes, Python
3 uses a print function instead of a print statement. If you want to
follow along with the problems, use the version of Python it uses (2.7
is probably safe if there isn't a version specified).
 
V

Vlastimil Brom

2012/3/10 sl33k said:
I'm trying project euler problem 3 and I've hit the wall with this
error. What could be the problem here?

 l=[]...     if num%i==0:
...         l.append(i)
...     i+=1
... print max(l)
 File "<stdin>", line 5
   print max(l)
       ^
SyntaxError: invalid syntax

Hi,
if you are using python 3, you'd (most likely) need to adapt the code
written for python 2.
see:
http://docs.python.org/py3k/whatsnew/3.0.html#print-is-a-function

hth,
vbr
 
L

liuerfire Wang

在 2012å¹´3月10日星期六UTC+8下åˆ8æ—¶34分35秒,sl33k写é“:
I'm trying project euler problem 3 and I've hit the wall with this
error. What could be the problem here?

l=[]... if num%i==0:
... l.append(i)
... i+=1
... print max(l)
File "<stdin>", line 5
print max(l)
^
SyntaxError: invalid syntax

It is a indentation error. It should be like:
.... if num%i==0:
.... l.append(i)
.... i+=1
....
 
G

Günther Dietrich

sl33k said:
I'm trying project euler problem 3 and I've hit the wall with this
error. What could be the problem here?

l=[]... 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.



Best regards,

Günther
 
I

Ian Kelly

 sl33k said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top