Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.

Paste

Pasted as Python by scurl ( 13 years ago )
# import C math library in order to use the log() function
from math import *
compare=2
tocheckifprime=2
#create empty list to fill with the prime number logs
primelogs=[]
#ask for input number, int ensures the program errors out if the input isn't a whole number
input_number=int(raw_input('Please enter a whole number for me to work with: '))
while tocheckifprime<=input_number:
#checks for remainder in order to find primes
    brainfart=tocheckifprime%compare
#if there's a remainder, add one to 'compare' then recheck against 'tocheckifprime'. faster if i cut out even #s
    if brainfart>0:
        compare+=1
    elif brainfart==0:
        if compare==tocheckifprime:
#if it's found a prime, then it computes the log of it and appends that to the primelogs list
            primelogs.append(log(tocheckifprime))
            tocheckifprime+=1
#resets 'compare' for next number check
            compare=2
#if it hasn't found a prime, resets compare and goes to the next num. in the checklist
        else:
            tocheckifprime+=1
            compare=2
# when list gets to input number, finds sum of all logs in the primelogs list, assigns the sum a variable name, and prints out the info            
if tocheckifprime>=input_number:
# just to check if prime logs are correct
    ##print (primes)
    some = sum(primelogs)
    print "The number you entered was: " + str(input_number)
    print "The sum of the logs of the primes between 2 and " + str(input_number) + " is " + str(some)

 

Revise this Paste

Children: 65157
Your Name: Code Language: