python输出200以内的素数

Posted jie828

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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

以上是关于python输出200以内的素数的主要内容,如果未能解决你的问题,请参考以下文章