Syntax error help

This is the place for queries that don't fit in any of the other categories.

Syntax error help

Postby lorentz » Mon Jun 10, 2013 5:23 pm

Hello,

I keep getting a syntax error on line 7 of my code and I can't see why.

Code: Select all
import math

total = 0
sign = math.atan(math.sqrt(2) - 1)
for n in xrange(0, 500):
   t = (math.pow(sign, ((n * 2) + 1)) / ((n * 2) + 1)
   total = total + t
   sign = sign * -1
   
print total * 8


Any help you can give would be appreciated,

lorentz.
lorentz
 
Posts: 9
Joined: Mon May 27, 2013 4:46 pm

Re: Syntax error help

Postby Yoriz » Mon Jun 10, 2013 5:51 pm

You have an open bracket before math.pow
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Image
User avatar
Yoriz
 
Posts: 1017
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: Syntax error help

Postby lorentz » Mon Jun 10, 2013 6:02 pm

I do, but they do close before my divide sign.

They do look somewhat unnecessary but I don't think that's what is causing the problem.

total = total + t

Is where the error lies. On a side note, will it return all the errors at once, or as I fix each one will it move onto the next?
lorentz
 
Posts: 9
Joined: Mon May 27, 2013 4:46 pm

Re: Syntax error help

Postby Yoriz » Mon Jun 10, 2013 6:05 pm

Yes that is the problem, remove that open bracket and the error will go away.
You have uneven amount of open to close brackets, that first bracket opens but never closes which is causing the error on the following line.
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Image
User avatar
Yoriz
 
Posts: 1017
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: Syntax error help

Postby lorentz » Mon Jun 10, 2013 6:08 pm

Oh, you are right. I was missing that.

Thank you very much!
lorentz
 
Posts: 9
Joined: Mon May 27, 2013 4:46 pm

Re: Syntax error help

Postby Yoriz » Mon Jun 10, 2013 6:23 pm

lorentz wrote: On a side note, will it return all the errors at once, or as I fix each one will it move onto the next?


It will stop on the first error.
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Image
User avatar
Yoriz
 
Posts: 1017
Joined: Fri Feb 08, 2013 1:35 am
Location: UK


Return to General Coding Help

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot], hickadee and 1 guest