A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 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, ".";
anonymous
 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

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0I 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.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0The 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.
Ask your own question
Sign UpFind more explanations on OpenStudy
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
 Engagement 19 Mad Hatter
 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.