The guide I am reading says to try to make: "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."
It seems like they are saying to make it do: log(sum) / log(n)
However, that does not give a limit of 1...
Here is the code I have, with the part highlighted
from math import *
nPrime = int(input("n = "))
if nPrime <= 0:
print "dsfsdfsds"
else:
finalPrime = 1
verifiedPrimeCount = 0
mightBePrime = finalPrime + 1
stackPrimes = 0
while verifiedPrimeCount < nPrime:
primeCheck = True
for divideBy in xrange(2, mightBePrime, 1):
if primeCheck:
primeCheck = ((mightBePrime % divideBy) != 0)
if primeCheck:
finalPrime = mightBePrime
stackPrimes = stackPrimes + finalPrime
verifiedPrimeCount = verifiedPrimeCount + 1
[b]print stackPrimes, "||", (log(stackPrimes)) / (log(nPrime))[/b]
mightBePrime = mightBePrime + 1
For example, I get this with N=10:
Quote
2 || 0.301029995664
5 || 0.698970004336
10 || 1.0
17 || 1.23044892138
28 || 1.44715803134
41 || 1.61278385672
58 || 1.76342799356
77 || 1.88649072517
100 || 2.0
129 || 2.1105897103
5 || 0.698970004336
10 || 1.0
17 || 1.23044892138
28 || 1.44715803134
41 || 1.61278385672
58 || 1.76342799356
77 || 1.88649072517
100 || 2.0
129 || 2.1105897103
I just started learning python 2 days ago... sorry if this is a stupid question.
Thanks.


Sign In
Create Account

Back to top









