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
posted @ 2012-10-19 23:26  hnrainll  阅读(2625)  评论(0编辑  收藏  举报