A community for students.
Here's the question you clicked on:
 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
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

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0sorry it didn't post the bottom but it ends with primecount= primecount 1 print answer

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

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

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

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0thanks, got it working
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.