anonymous
  • anonymous
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!
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
schrodinger
  • schrodinger
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
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
e.mccormick
  • e.mccormick
Are you just trying to find the n\(^{th}\) prime? Because it also skips 2 and 3....
e.mccormick
  • e.mccormick
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.

Looking for something else?

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

More answers

e.mccormick
  • e.mccormick
Oh... one last thing, you are doing an import math... why?
e.mccormick
  • e.mccormick
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/
e.mccormick
  • e.mccormick
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/
anonymous
  • anonymous
@theo92 - i added some print statements to your code.
anonymous
  • anonymous
Thank you, with your advice i could fix the problem.

Looking for something else?

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