anonymous
  • anonymous
I did problem set 1a after the second lecture and was able to get something to work. After the third lecture, I went back and tried to incorporate some of the new stuff. However, I seem to have a snag that I can't seem to figure out. It does great until x=25. It finds the 24th prime (change x to 24), but when x is 25 it returns 95 as a prime number. Any thoughts? x = 25 ##to stop when reaching the Xth prime number count = 1 ##count starts at one since it will miss 2, the first prime # prime_n = 1 ##testing number while (count
MIT 6.00 Intro Computer Science (OCW)
jamiebookeater
  • jamiebookeater
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
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.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this
and thousands of other questions

anonymous
  • anonymous
Full Code: x = 25 ##to stop when reaching the Xth prime number count = 1 ##count starts at one since it will miss 2, the first prime # prime_n = 1 ##testing number while (count
anonymous
  • anonymous
if you use dpaste.com or something similar to post your code it is easier for everyone. first - don't forget that the range function will return a list that does NOT contain the "stop" number - prime_n/2 in this case. next - it looks like you are changing the number you are testing within the loop that changes the divisor - that can lead to incorrect results - putting print statements in your is a good debugging tool, i've put a print statement in your code that will let you see what is happening http://dpaste.com/545075/.
anonymous
  • anonymous
Thanks a ton. I see what the problem is now. It is moving on to the next prime and continuing with the same number for the test divisor. Should have done this check before posting, but I'm still learning. Thanks

Looking for something else?

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