python 求N以内的所有的质数

import sys
def isPrime(num):
    i = 2
    while i < num:
        if 0 == (num%i):
            return False         
        else:
            i = i + 1
    return True

if __name__ == '__main__':
    iInput = int(raw_input('Assign a number N:'))
    for j in range(2, iInput + 1):
        if(isPrime(j)):
            print j

转载于:https://my.oschina.net/u/179109/blog/84014

你可能感兴趣的:(python 求N以内的所有的质数)