使用python实现打印所有100以内的所有质数
2016-03-13 19:19
2031 查看
def getprim(n): p=2 x=0 while(x<n): result=True for i in range(2,p-1): if(p%i==0): result=False#如果P能被任意一个小于n的数整除,则非质数 if result==True: print p, #如果是质数,则打印 x=x+1#计数+1 p+=1#P+1 getprim(100)
print filter(lambda x:not any(map(lambda y:x%y==0 ,range(2,x))),range(2,100))
相关文章推荐
- 理解 Python 中的 *args 和 **kwargs
- python 一百行代码将图片转成字符画
- opencv on python 安装
- [转载] Python 列表(list)、字典(dict)、字符串(string)常用基本操作小结
- 树回归预测
- python之smtplib发邮件
- 模型树------构建模型树
- [leetcode] @python 113. Path Sum II
- python安装scipy与sklearn模块
- [leetcode] @python 112. Path Sum
- Numpy 基础教程
- [leetcode]@python 111. Minimum Depth of Binary Tree
- 回归树-----生成回归树
- 用conda管理Python包
- win7下python3.4读写中文文件不乱码
- Python多线程中join函数与setDaemon函数使用说明
- Python多线程中join函数与setDaemon函数使用说明
- 简单讲解Python中的字符串与字符串的输入输出
- 100 numpy exercises
- NumPy的教程--数组,基本运算