Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 weird syntax error
Index -> Programming, Python -> Python Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
saltpro15




PostPosted: 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
Sponsor
sponsor
andrew.




PostPosted: 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




PostPosted: 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
andrew.




PostPosted: 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




PostPosted: Mon Sep 14, 2009 6:05 pm   Post subject: RE:weird syntax error

hahahaha fail on my part.


thanks guys
DtY




PostPosted: Mon Sep 14, 2009 6:06 pm   Post subject: RE:weird syntax error

Oh, and no end, python is completely layout based
andrew.




PostPosted: 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




PostPosted: 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?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
saltpro15




PostPosted: 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
Display posts from previous:   
   Index -> Programming, Python -> Python Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: