A community for students.
Here's the question you clicked on:
 0 viewing
bzoo
 4 years ago
I am working on problem set 1 and have hit a bit of a wall. Can somebody help?
bzoo
 4 years ago
I am working on problem set 1 and have hit a bit of a wall. Can somebody help?

This Question is Closed

Aslander
 4 years ago
Best ResponseYou've already chosen the best response.0What have you tried so far?

bzoo
 4 years ago
Best ResponseYou've already chosen the best response.0primeCounter = 1 numbertoTest = 3 while primeCounter < 1000: for divisor in range (2, numbertoTest): if numbertoTest % divisor == 0: numbertoTest = numbertoTest + 2 else: divisor = divisor + 1 if numbertoTest != 0: primeCounter = primeCounter + 1 numbertoTest = numbertoTest + 2 print numbertoTest

Keen
 4 years ago
Best ResponseYou've already chosen the best response.0I think you should experiment a bit with how for loops work, the else: divisor = divisor + 1 section doesn't do anything. Also, why are you checking to see if numbertoTest doesn't equal zero? Where and why would your code set it to zero? Both those are tangential to the problem your having though. What's the algorithm you're using? Describe it in as much detail as possible.

Aslander
 4 years ago
Best ResponseYou've already chosen the best response.0Looking at your first if/else loop. If the number is 9. Range will be 2,9. So...9/2 has a remainder. Div + 1. 9/3 = no remainder. so, add 2 to numerator. 11/3 = no remainder. Add 1 to divisor. 11/4  no rem. 11/5 no remainder, etc, up to 11/10, then no remainder, so go to next IF statement where the counter is increased. Your algorithm is incorrect. You need a command to break the cycle, before you do all the calculations for the entire range of "divisor in range(2,numbertoTest).

Aslander
 4 years ago
Best ResponseYou've already chosen the best response.0I made some typos...please forgive me  so text should be: Looking at your first if/else loop. If the number is 9. Range will be 2,9. So...9/2 has a remainder. Div + 1. 9/3 = no remainder. so, add 2 to numerator. 11/3 = remainder. Add 1 to divisor. 11/4  rem. 11/5 remainder, etc, up to 11/10, then remainder, so go to next IF statement where the counter is increased. Your algorithm is incorrect. You need a command to break the cycle, before you do all the calculations for the entire range of "divisor in range(2,numbertoTest).
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.