怎样用Python判断101-200有多少素数并输出

时间:2024-10-11 21:07:05

1、首先,右键点击【项目】,创建一个【Python】文件

怎样用Python判断101-200有多少素数并输出

2、接着,在右侧输入代码,代码写在【下一步】

怎样用Python判断101-200有多少素数并输出

3、然后,复制代码粘贴到文件中h = 0leap = 1from math import sqrtfrom sys import stdoutfor m in range(101,201): k = int(sqrt(m + 1)) for i in range(2,k + 1): if m % i == 0: leap = 0 break if leap == 1: print ('%-4d' % m) h += 1 if h % 10 == 0: print ('') leap = 1print ('The total is %d' % h)

怎样用Python判断101-200有多少素数并输出

4、随后,右键选择运行代码文件

怎样用Python判断101-200有多少素数并输出

5、最后,在最下面就可以看到运行结果了

怎样用Python判断101-200有多少素数并输出
© 手抄报圈