[ create a new paste ] login | about

Link: http://codepad.org/ALTEQij0    [ raw code | output | fork ]

Python, pasted on Jan 20:
#
#Name: Product of Prime
#Author: Douglas Welcome
#Date: 1/3/11
#Objectives of the program: Compare the product of primes<n to e**n
#



number=3 #start with 3 because we know 2 is prime
divisor=2
counter=1#start with 1 because 2 is already prime
 
answer=raw_input("Please try a number in this magic equation machine:")#lets the user decide the prime to calculate to
print "You are caculating to the", answer + "th prime. It is:"
n=int(answer)




while counter<n: #this calculates to whatever whatever the user decides n to be
    if number%divisor!=0: #this tests if the number has an even remainder
        if  divisor<(number): #this works through the possible divisors from 2 to the number being tested
            divisor+=1
    
        if  divisor>=(number): #once the divisor reaches the number being tested, it adds 2 to the number being tested
            number+=2 #runs through odd numbers
            divisor=2 #resets divisor
            counter+=1 #advances the counter because the number is prime
    else:
        number+=2 #the number is not prime, advances to next odd number and resets divisor
        divisor=2
        
answer=number-2 #because 2 was added to the prime, we have to subtract 2 to get the answer

print answer #prints answer


Output:
1
2
3
4
Please try a number in this magic equation machine:Traceback (most recent call last):
  Line 14, in <module>
    answer=raw_input("Please try a number in this magic equation machine:")#lets the user decide the prime to calculate to
EOFError


Create a new paste based on this one


Comments: