python输出200以内的素数

i = 2
while i <= 200:
    isPrimeNumber = True
    j = 2
    while j < i:
        if(i % j == 0):
            isPrimeNumber=False
            break
        j += 1
    if(isPrimeNumber == True):
        print("%d" % i)
    i += 1
import math

i = 2
while i <= 200:
    m = int(math.sqrt(i))
    isPrimeNumber = True
    j = 2
    while j <= m:
        if(i % j == 0):
            isPrimeNumber=False
            break
        j += 1
    if(isPrimeNumber == True):
        print("%d" % i)
    i += 1
文章来自:https://www.cnblogs.com/jie828/p/12455794.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3