I've been learning Python 2.5.4 and I have the following problem to solve:
"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."
This is what I have so far:
from math import *
n = raw_input('This is a logarithm ratio tester. Which number do you want to test? ')
for x in range(2,n): #picks numbers to test
for divisor in range(2, 1+int(sqrt(x+1))):
if x%divisor == 0: #checks if x is prime
log(x) #computes log of prime
Unfortunately I'm not sure how to implement a function for summing all the logs. I would imagine that once I have that, I just need to conclude the program with:
print 'Sum of the logs of the primes is',logsum
print 'n =',n
print 'Ratio of sum to n is',logsum/n
Or some variant. But what would be a good way to obtain what I've labeled logsum? Please note I have been studying programming for no more than a week, I know very few statements/functions by heart, and I am not a mathematician. When in doubt, assume I'm an idiot. Thanks!