A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 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: "))

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

    sorry function ps2 should be called something like printLogInfo

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

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

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

    Thanks!

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