Author |
Message |
saltpro15
|
Posted: Mon Sep 14, 2009 3:45 pm Post subject: weird syntax error |
|
|
Hey guys, I'm working on a project euler problem in python and I'm getting a weird syntax error...
Python: |
def appearances_in_factorial(p,n)
s = 0
while n > 0
n /= p
sum += n
end
return s
end
|
I'm using IDLE, and the error I get is syntax error, and all the white space after (p,n) is highlighted red... any ideas? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
andrew.
|
Posted: Mon Sep 14, 2009 6:04 pm Post subject: RE:weird syntax error |
|
|
You need the ":" to tell python that you are putting something in that method. You also need it after the while loop. |
|
|
|
|
|
DtY
|
Posted: Mon Sep 14, 2009 6:04 pm Post subject: RE:weird syntax error |
|
|
Forgot a colon on the first line, and on the while
[edit] Late |
|
|
|
|
|
andrew.
|
Posted: Mon Sep 14, 2009 6:05 pm Post subject: RE:weird syntax error |
|
|
I wanted to edit my post to include this:
Python: | def appearances_in_factorial(p,n):
s = 0
while n > 0:
n /= p
sum += n
end
return s
end
|
|
|
|
|
|
|
saltpro15
|
Posted: Mon Sep 14, 2009 6:05 pm Post subject: RE:weird syntax error |
|
|
hahahaha fail on my part.
thanks guys |
|
|
|
|
|
DtY
|
Posted: Mon Sep 14, 2009 6:06 pm Post subject: RE:weird syntax error |
|
|
Oh, and no end, python is completely layout based |
|
|
|
|
|
andrew.
|
Posted: Mon Sep 14, 2009 6:09 pm Post subject: RE:weird syntax error |
|
|
Yeah, take out the end. I forgot to take that out. |
|
|
|
|
|
Tony
|
Posted: Mon Sep 14, 2009 7:35 pm Post subject: RE:weird syntax error |
|
|
FYI, the function will always return 0. Is "s" and "sum" supposed to be the same variable? |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Sponsor Sponsor
|
|
|
saltpro15
|
Posted: Mon Sep 14, 2009 7:36 pm Post subject: RE:weird syntax error |
|
|
yeah, I fixed it. Thanks guys
and Tony, yes : P I just forgot to change s to sum at the end |
|
|
|
|
|
|