A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 5 years ago
Can someone please review my ps1b? I'd appreciate any feedback.
import math
def isPrime(num):
if num > 1:
if num == 2:
return 1
i = 2
while i < math.sqrt(num) + 1:
if num%i == 0:
return 0
else:
i += 1
return 1
else:
return 0
def ps2(num):
i = 2
j = 0
logsum = math.log(2)
while j < num:
if isPrime(i) == 1:
j += 1
logsum += math.log(i)
if j == num:
print "N: ",num
print "Sum of logs: ",logsum
print "Ratio: ",num/logsum
i = i + 1
ps2(input("Enter a number: "))
anonymous
 5 years ago
Can someone please review my ps1b? I'd appreciate any feedback. import math def isPrime(num): if num > 1: if num == 2: return 1 i = 2 while i < math.sqrt(num) + 1: if num%i == 0: return 0 else: i += 1 return 1 else: return 0 def ps2(num): i = 2 j = 0 logsum = math.log(2) while j < num: if isPrime(i) == 1: j += 1 logsum += math.log(i) if j == num: print "N: ",num print "Sum of logs: ",logsum print "Ratio: ",num/logsum i = i + 1 ps2(input("Enter a number: "))

This Question is Closed

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0sorry function ps2 should be called something like printLogInfo

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.02 problems. 1) The ratio should be the (sum of logs not including the nth prime)/the nth prime. In your problem, you divide 1000 by the sum of logs including the nth prime. This is wrong. 2) Note that you must not include the math.log(7919) in your Sum. The sum should be close to 7803 I believe. 3) I checked your problem. You add math.log(2) twice in your problem. Remove one to get 7803.3 which is the correct answer.
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.