A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

hi, i am having trouble with problem 2 of ps1. I keep either getting wrong numbers or nothing. Can someone please help me. Thanks This is what I have so far. import math answer=math.log(2) primecount=0 candidate=1 while primecount<999: candidate=candidate+2 divisor=3 not_prime = False while (divisor<candidate/2) and (not_prime == False): if candidate%divisor == 0: not_prime = True divisor = divisor+2 while primecount<998 and not_prime == False: answer= answer + math.log(candidate) if not_prime == False: primecount = primecou

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

    sorry it didn't post the bottom but it ends with primecount= primecount 1 print answer

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

    Were you able to do Problem 1? You only need to make some very minor changes to the solution for problem 1 to get it to solve problem 2. I'd reccomend starting with problem 1 and modifying it to solve problem 2. If you want some tips, copy and paste your problem 1 solution and I or somebody else here may be able to advise you.

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

    this is my solution to problem 1, I would appreciate any help with problem 2. primecount=0 candidate=1 while primecount<999: candidate=candidate+2 divisor=3 not_prime = False while (divisor<candidate/2) and (not_prime == False): if candidate%divisor == 0: not_prime = True divisor = divisor+2 if not_prime == False: primecount= primecount+1 print candidate

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

    Okay, I see what you've changed between the two. Get rid of the "while primecount<998 and not_prime == False:" at the end. Move "answer= answer + math.log(candidate)" into the last if statement. It should work then.

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

    thanks, got it working

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

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.