Problem with Threads

Kwnstantinos Euaggelidis euaggelidiskwn at gmail.com
Wed Dec 19 18:11:37 CET 2012


I have this code for Prime Numbers and i want to do it with Threads.. Any idea.??

# prime numbers are only divisible by unity and themselves
# (1 is not considered a prime number by convention)
import time
def isprime(n):
    if n == 2:
        return 1
    if n % 2 == 0:
        return 0
    max = n**0.5+1
    i = 3
    while i <= max:
        if n % i == 0:
            return 0
        i+=2
    return 1
print "Please give the maximum number"
endnum = input()
start = time.time()
for i in range(endnum):
    if isprime(i) == 1:
        print "Number %d is PRIME" % i
print "Elapsed Time: %s" % (time.time() - start)



More information about the Python-list mailing list