A community for students.
Here's the question you clicked on:
 0 viewing
lucifer
 4 years ago
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.
lucifer
 4 years ago
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.

This Question is Closed

lucifer
 4 years ago
Best ResponseYou've already chosen the best response.0if p = x if the value of x has been assigned to p. I said both are numbers...

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0dont forget to save your work as .py

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0you 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

lucifer
 4 years ago
Best ResponseYou've already chosen the best response.0I see. it runs but doesn't do what I want :(

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0Hi. 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!)

lucifer
 4 years ago
Best ResponseYou've already chosen the best response.0i 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.

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0Sorry, 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!

lucifer
 4 years ago
Best ResponseYou've already chosen the best response.0... it doesn't seem to work, project bloke. But I'll try to use your idea  when I muster enough motivation. This is hard.

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0odd... 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.

lucifer
 4 years ago
Best ResponseYou've already chosen the best response.0oh... yes, it works. I forgot to enter testsumlogs(). sorry. this helps. thx
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.