Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

theo92 Group Title

My calculation of primenumbers is nearly working out, only sometimes it gives a primenumber that is not a primenumber at all, like 5405, 5615, 6035 or even 95. I find it really weird and do not see why this happens... My Code is here: http://dpaste.com/1324943/ Thank you guys!

  • 11 months ago
  • 11 months ago

  • This Question is Closed
  1. bwCA Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    the % operator might help http://docs.python.org/2.7/library/stdtypes.html#numeric-types-int-float-long-complex strategically placed print statements can help alot - it shows you what is going on in your code

    • 11 months ago
  2. e.mccormick Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Are you just trying to find the n\(^{th}\) prime? Because it also skips 2 and 3....

    • 11 months ago
  3. e.mccormick Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    And you forgot to reset your divisor when you find something is non-prime, so the test point is past 5 when it checks 95.

    • 11 months ago
  4. e.mccormick Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    Oh... one last thing, you are doing an import math... why?

    • 11 months ago
  5. e.mccormick Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    I made a fixed version. I suggest playing with mod, %, like bwCA says and resetting divisor to 3 on failures. If that does not do it, then look at the fixed version. http://dpaste.com/hold/1325399/

    • 11 months ago
  6. e.mccormick Group Title
    Best Response
    You've already chosen the best response.
    Medals 1

    This one is also based on yours, does not use %, and deals with another issue... the +2 after finding the last prime! http://dpaste.com/hold/1325422/

    • 11 months ago
  7. bwCA Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    @theo92 - i added some print statements to your code.

    • 11 months ago
  8. theo92 Group Title
    Best Response
    You've already chosen the best response.
    Medals 0

    Thank you, with your advice i could fix the problem.

    • 11 months ago
    • Attachments:

See more questions >>>

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.