这个是照我以前C语言写的输出质数博客改的,博客地址
myarr = [0, 1, 3, 4, 6, 7, 8, 100, 101, 103, 104, 107, 110, 111]
def isprime(n):
if n == 1 or n == 0:
return False
elif n == 2:
return True
else:
a = False # /a=1时为质数 a=0为合数
count = n
for i in range(2, count, 1):
if n % i == 0:
a = False
break
else:
a = True
count = int(n / i) + 1;
return a
if __name__ == '__main__':
print('myarr列表中,素数是:', end='')
for i in myarr:
if isprime(i) == True:
print(i, end=' ')
m y a r r = [ 0 , 1 , 3 , 4 , 6 , 7 , 8 , 100 , 101 , 103 , 104 , 107 , 110 , 111 ] myarr = [0, 1, 3, 4, 6, 7, 8, 100, 101, 103, 104, 107, 110, 111] myarr=[0,1,3,4,6,7,8,100,101,103,104,107,110,111]
输出结果
m y a r r 列 表 中 , 素 数 是 : 3 7 101 103 107 myarr列表中,素数是:3\quad7 \quad101\quad 103\quad 107 myarr列表中,素数是:37101103107