Monday, August 17, 2015

how to find prime number using array in python

import time
__author__ = 'Polo-Dev'

def is_prime(pList, number):
    for i in pList:
        if number % i == 0:
            return False
    return True



def main(given_number):
    pList = []
    for i in range(2, given_number):
        if is_prime(pList, i):
            pList.append(i)
            print(i)
    print(pList)
start_time = time.time()
main(100000)
end_time = time.time()
time_needed = float(end_time - start_time)
print(time_needed)

No comments:

Post a Comment

css snippet for blogger code highlighting

code, .code {     display: block;     background: beige;     padding: 10px;     margin: 8px 15px; }