python 获得质数
def is_prime(n): '''检测大于1,除自身外是否可以其他自然数整除''' if n <= 1: return False for i in range(2, n): if n % i == 0: return False return True prime_number = [] def prime(n): for i in range(0, n): if is_prime(i): prime_number.append(i) n=1000 prime(n) num=len(prime_number) for i in range(0,num): print(prime_number[i]) print ("n="+str(n)+",num="+str(num))