A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing


  • 5 years ago

I seem to have got myself into a endless loop on the finding the 100th prime number project and cant see what is causing it any help anyone could give me would be appreciated. Here is my code. primeCount = 2 primeCheck = 3.0; divisor = 2; result = 0; while primeCount <= 1000: while divisor < primeCheck/2: result = primeCheck % divisor; if result == 0: primeCount = primeCount + 1; primeCheck = primeCheck + 2; else: divisor = divisor + 1; print "The 1000th prime number is ", primeCheck, ".";

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

    I might be reading this wrong, but you never increment divisor in the second while loop. So once you get primeCheck up to 5 it can't escape that loop. The rest seems ok.

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

    The logic here is missing something. Try steping through the code one line at a time with a paper/pencil, and at each line write the current values for primeCount, divisor, primeCheck, and result. Also you can try adding print statements to see where your code is getting stuck.

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


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