I am learning Python 2.5.4 and I have the following problem:
"Write a program that calculates the sum of the logarithms of all primes from 2 to a certain number n and displays the sum of the logs of primes, the number n and the ratio of these two quantities. This is 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 to summarize all the logs. I would suggest that as soon as I succeed, I just need to complete the program:
print 'Sum of the logs of the primes is',logsum
print 'n =',n
print 'Ratio of sum to n is',logsum/n
Or some option. But what would be a good way to get what I called logsum? Please note that I have been learning programming for no more than a week, I know very few statements / functions by heart, and I'm not a mathematician. If in doubt, assume I'm an idiot. Thanks!