I don't understand why it says invalid syntax. the program is supposed to sum the logs of all the primes til some given number.
if p = x if the value of x has been assigned to p. I said both are numbers...
dont forget to save your work as .py
why is that?
Is my style bad btw ?
you need two equal signs because you're doing a comparison and not an assignment. where your error is: instead of p=x it should be p==x
I see. it runs but doesn't do what I want :(
Hi. There seem to be a couple of issues with the function check(x) - the 'else' statement isn't indented with its matching 'if', and it seems to be eliminating any even numbers and then allocating any odd numbers to a global variable. (I've not got to the point of using global variables yet, so I can't comment on those!) Also, in checkthenmaybeaddtil(n), you're initializing S in the recursion, so it will continue to reset itself. You could initialize this outside of the function to make sure it's recognized within it? Also, x is being initialized twice - once as 'global x' (if that's how it works....) and again as part of the for statement. (I approached this problem from a completely different angle, so I'm afraid I can't be of much further help at this time GMT unless you want to take a look at a code paste!)
i do. It always helps to see other people's codes. I'm totally incompetent in programming but I would imagine that people learn to program properly just like they learn to be eloquent -- by reading eloquent writings, etc. I will now try your suggestions. bwt it is weird that I had to learn about global variables just for this assignment.
Sorry, nearly fell asleep in the shower there!! Here's a link to my code - took a few minutes to find it too: http://codepad.org/e8gDtHCd (I just iterated through for this one - didn't touch recursion until PS2) I've not touched globals yet, but I'm gonna take a break tomorrow to revise some of the readings so hopefully they'll make a bit more sense to me soon!
... it doesn't seem to work, project bloke. But I'll try to use your idea -- when I muster enough motivation. This is hard.
odd... it's working for me - just had to try it in case though :p I've actually done a little bit of programming in the past (just VB) and it IS tough to begin with, but stick in there. When the light begins to dawn, it's an amazing feeling.
oh... yes, it works. I forgot to enter testsumlogs(). sorry. this helps. thx
Join our real-time social learning platform and learn together with your friends!