当前位置:网站首页>实例036:算素数
实例036:算素数
2022-08-04 01:35:00 【懒笑翻】
题目:求100之内的素数。
程序分析:用else执行for循环的奖励代码(如果for是正常完结,非break)。
代码:
lo = int(input('下限:'))
hi = int(input('上限:'))
for i in range(lo, hi + 1):
if i > 1:
for j in range(2, i):
if (i % j) == 0:
break
else:
print(i, end=' ')
"""
* @Author: xiaofang
* @Description:
学习中遇到问题没人解答?小编创建了一个Python学习交流QQ群,扫码下方QQ群二维码即可
寻找有志同道合的小伙伴,互帮互助,群里还有不错的视频学习教程和PDF电子书!
"""
结果:
边栏推荐
- nodejs 安装多版本 版本切换
- html select标签赋值数据库查询结果
- nodejs+npm的安装与配置
- typescript55 - generic constraints
- 字符串变形
- typescript51 - basic use of generics
- 如何通过API接口从淘宝(或天猫店)复制宝贝到拼多多接口代码对接教程
- Electronics manufacturing enterprise deployment WMS what are the benefits of warehouse management system
- JS 从零教你手写节流throttle
- Slipper - virtual point, shortest path
猜你喜欢
如何用C语言代码实现商品管理系统开发
观察者模式
nodejs installation and environment configuration
typescript57 - Array generic interface
企业虚拟偶像产生了实质性的价值效益
typescript52-简化泛型函数调用
持续投入商品研发,叮咚买菜赢在了供应链投入上
Continuing to invest in product research and development, Dingdong Maicai wins in supply chain investment
Web3 security risks daunting?How should we respond?
redis中常见的问题(缓存穿透,缓存雪崩,缓存击穿,redis淘汰策略)
随机推荐
typescript52 - simplify generic function calls
Summary of GNSS Articles
Quickly build a website with static files
螺旋矩阵_数组 | leecode刷题笔记
特征值与特征向量
Vant3 - click on the corresponding name name to jump to the next page corresponding to the location of the name of the TAB bar
nodejs install multi-version version switching
ThreadLocal
2022 中国算力大会发布“创新先锋”优秀成果
5. Scrapy middleware & distributed crawler
持续投入商品研发,叮咚买菜赢在了供应链投入上
5.scrapy中间件&分布式爬虫
flask框架初学-06-对数据库的增删改查
LeetCode第三题(Longest Substring Without Repeating Characters)三部曲之三:两次优化
字符串的排列
IDEA02:配置SQL Server2019数据库
【虚拟化生态平台】虚拟化平台esxi挂载USB硬盘
【store商城项目01】环境准备以及测试
nodejs 安装多版本 版本切换
ASP.NET 获取数据库的数据并写入到excel表格中