Got Homework?
Connect with other students for help. It's a free community.
Here's the question you clicked on:
 0 viewing
bzoo
Group Title
I am working on problem set 1 and have hit a bit of a wall. Can somebody help?
 3 years ago
 3 years ago
bzoo Group Title
I am working on problem set 1 and have hit a bit of a wall. Can somebody help?
 3 years ago
 3 years ago

This Question is Closed

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

bzoo Group TitleBest ResponseYou've already chosen the best response.0
primeCounter = 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
 3 years ago

Keen Group TitleBest ResponseYou've already chosen the best response.0
I 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.
 3 years ago

Aslander Group TitleBest ResponseYou've already chosen the best response.0
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 = 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).
 3 years ago

Aslander Group TitleBest ResponseYou've already chosen the best response.0
I 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).
 3 years ago
See more questions >>>
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.