Quantcast

Got Homework?

Connect with other students for help. It's a free community.

  • across
    MIT Grad Student
    Online now
  • laura*
    Helped 1,000 students
    Online now
  • Hero
    College Math Guru
    Online now

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

bzoo

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
  1. Aslander
    Best Response
    You've already chosen the best response.
    Medals 0

    What have you tried so far?

    • 3 years ago
  2. bzoo
    Best Response
    You've already chosen the best response.
    Medals 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
  3. Keen
    Best Response
    You've already chosen the best response.
    Medals 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
  4. Aslander
    Best Response
    You've already chosen the best response.
    Medals 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
  5. Aslander
    Best Response
    You've already chosen the best response.
    Medals 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
    • Attachments:

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