
-----------------------------------
saltpro15
Mon Sep 14, 2009 3:45 pm

weird syntax error
-----------------------------------
Hey guys, I'm working on a project euler problem in python and I'm getting a weird syntax error...


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?

-----------------------------------
andrew.
Mon Sep 14, 2009 6:04 pm

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
Mon Sep 14, 2009 6:04 pm

RE:weird syntax error
-----------------------------------
Forgot a colon on the first line, and on the while

[edit] Late :(

-----------------------------------
andrew.
Mon Sep 14, 2009 6:05 pm

RE:weird syntax error
-----------------------------------
I wanted to edit my post to include this:
def appearances_in_factorial(p,n):
    s = 0 
    while n > 0:
        n /= p 
        sum += n 
    end 
    return s 
end 


-----------------------------------
saltpro15
Mon Sep 14, 2009 6:05 pm

RE:weird syntax error
-----------------------------------
hahahaha fail on my part.


thanks guys

-----------------------------------
DtY
Mon Sep 14, 2009 6:06 pm

RE:weird syntax error
-----------------------------------
Oh, and no end, python is completely layout based

-----------------------------------
andrew.
Mon Sep 14, 2009 6:09 pm

RE:weird syntax error
-----------------------------------
Yeah, take out the end. I forgot to take that out.

-----------------------------------
Tony
Mon Sep 14, 2009 7:35 pm

RE:weird syntax error
-----------------------------------
FYI, the function will always return 0. Is "s" and "sum" supposed to be the same variable?

-----------------------------------
saltpro15
Mon Sep 14, 2009 7:36 pm

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
