A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

Could someone take a look at my code for ps1b? Thanks.

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

    Here is the solution I came up with. It works, but for numbers above 20,000 or so, it can take a little while to compute the answer. I was just wondering if there's a better/faster way to do it? from math import * n = input('Pick a number: ') sum = 0 for number in range(2,n): divisor = 2 while (divisor < (number/2)) and (number % divisor !=0): divisor = divisor + 1 if number % divisor != 0: prime_number = number sum = sum + log(prime_number) print sum + log(2) print n print (sum/n)

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

    Here is all the code, highlighted with comments, if you need it: http://dpaste.com/hold/450061/

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

    Last line, use this : print ((sum+log(2))/n) If not, you are not counting the log of 2 in your ratio and your theorem fails

  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.