质数求法

'''
方法1:
from math import *

def primeNumber(start,end):

num = 0
for i in range(start,end):
    flag = 0
    for j in range(2,int(sqrt(i))+1):
        if i%j == 0:
            break
        else:
            flag = flag + 1
    if flag == len(range(2,int(sqrt(i))+1)):
        print(i)
        num = num + 1
print(num)

start = 101
end = 201
primeNumber(start,end)

方法2:
l = []
for i in range(101,200):
for j in range(2,i-1):
if i%j ==0:
break
else: #这里逻辑其实不太好,循环完成
l.append(i)

print(l)
print("总数为:%d" % len(l))
'''

你可能感兴趣的:(质数求法)