A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 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.

  • This Question is Closed
  1. lucifer
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    if p = x if the value of x has been assigned to p. I said both are numbers...

    1 Attachment
  2. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    dont forget to save your work as .py

  3. lucifer
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    why is that?

  4. lucifer
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Is my style bad btw ?

  5. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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

  6. lucifer
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I see. it runs but doesn't do what I want :(

  7. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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!)

  8. lucifer
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  9. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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!

  10. lucifer
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 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.

  11. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  12. lucifer
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    oh... yes, it works. I forgot to enter testsumlogs(). sorry. this helps. thx

  13. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

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
  • 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.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.