Computer Science Canada

weird syntax error

Author:  saltpro15 [ 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?

Author:  andrew. [ 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.

Author:  DtY [ 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

Author:  andrew. [ 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

Author:  saltpro15 [ Mon Sep 14, 2009 6:05 pm ]
Post subject:  RE:weird syntax error

hahahaha fail on my part.


thanks guys

Author:  DtY [ Mon Sep 14, 2009 6:06 pm ]
Post subject:  RE:weird syntax error

Oh, and no end, python is completely layout based

Author:  andrew. [ Mon Sep 14, 2009 6:09 pm ]
Post subject:  RE:weird syntax error

Yeah, take out the end. I forgot to take that out.

Author:  Tony [ 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?

Author:  saltpro15 [ 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


: