Created
November 2, 2017 07:28
-
-
Save jerrypy/9b69f8d9a9d982d7e2dba57784897a53 to your computer and use it in GitHub Desktop.
MIT 6.00 Assignments solutions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Problem 1 b | |
Write a program that computes the sum of the logarithms of all the primes from 2 to some | |
number n, and print out the sum of the logs of the primes, the number n, and the ratio of these | |
two quantities. Test this for different values of n. | |
You should be able to make only some small changes to your solution to Problem 1 to solve this | |
problem as well. | |
''' | |
from math import log | |
def product(n): | |
sum = 0.0 | |
for i in range(2,n): | |
if is_prime(i): # see ps1a.py | |
sum += log(i) | |
print sum, n, sum/n | |
product(100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment