Author |
Message |
saltpro15
![](http://compsci.ca/v3/uploads/user_avatars/9776171634ced6278d14c2.png)
|
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? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
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. |
|
|
|
|
![](images/spacer.gif) |
DtY
![](http://compsci.ca/v3/uploads/user_avatars/8576159234be48b7a8b0e8.png)
|
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 ![Sad Sad](http://compsci.ca/v3/images/smiles/icon_sad.gif) |
|
|
|
|
![](images/spacer.gif) |
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
|
|
|
|
|
|
![](images/spacer.gif) |
saltpro15
![](http://compsci.ca/v3/uploads/user_avatars/9776171634ced6278d14c2.png)
|
Posted: Mon Sep 14, 2009 6:05 pm Post subject: RE:weird syntax error |
|
|
hahahaha fail on my part.
thanks guys |
|
|
|
|
![](images/spacer.gif) |
DtY
![](http://compsci.ca/v3/uploads/user_avatars/8576159234be48b7a8b0e8.png)
|
Posted: Mon Sep 14, 2009 6:06 pm Post subject: RE:weird syntax error |
|
|
Oh, and no end, python is completely layout based |
|
|
|
|
![](images/spacer.gif) |
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. |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
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. |
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
saltpro15
![](http://compsci.ca/v3/uploads/user_avatars/9776171634ced6278d14c2.png)
|
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 |
|
|
|
|
![](images/spacer.gif) |
|