Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Invalid syntax error

Reply
Thread Tools

Invalid syntax error

 
 
sl33k
Guest
Posts: n/a
 
      03-10-2012
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


 
Reply With Quote
 
 
 
 
Amit Sethi
Guest
Posts: n/a
 
      03-10-2012
Its an indentation error

--
A-M-I-T S|S
 
Reply With Quote
 
 
 
 
Andrew Berg
Guest
Posts: n/a
 
      03-10-2012
On 3/10/2012 6:34 AM, sl33k 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 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).

--
CPython 3.2.2 | Windows NT 6.1.7601.17640
 
Reply With Quote
 
Vlastimil Brom
Guest
Posts: n/a
 
      03-10-2012
2012/3/10 sl33k <(E-Mail Removed)>:
> 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
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list


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...-is-a-function

hth,
vbr
 
Reply With Quote
 
liuerfire Wang
Guest
Posts: n/a
 
      03-10-2012
在 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=[]
> >>> 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


It is a indentation error. It should be like:

>>> while i<=num:

.... if num%i==0:
.... l.append(i)
.... i+=1
....
>>> print max(l)

 
Reply With Quote
 
Gnther Dietrich
Guest
Posts: n/a
 
      03-10-2012
In article
<(E-Mail Removed)>,
sl33k <(E-Mail Removed)> 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.



Best regards,

Gnther
 
Reply With Quote
 
Ian Kelly
Guest
Posts: n/a
 
      03-10-2012
On Sat, Mar 10, 2012 at 6:17 AM, Gnther Dietrich
<(E-Mail Removed)> wrote:
> In article
> <(E-Mail Removed)>,
> *sl33k <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Syntax error? What syntax error? Assignment fo default values? Mark Richards Perl Misc 3 11-18-2007 05:01 PM
Invalid URI: There is an invalid sequence in the string. Error!! Patrick.O.Ige ASP .Net 1 07-02-2006 11:21 AM
WMI - invalid syntax error? py Python 2 12-30-2005 02:47 PM
Invalid Syntax Error gornk Computer Support 1 08-20-2004 02:50 PM
Intermittant redirect to Invalid Syntax Error page =?Utf-8?B?TWFyayBQaGFuaWRlcw==?= ASP .Net 0 02-16-2004 03:26 PM



Advertisments