当前位置:网站首页>实例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电子书!
"""结果:

边栏推荐
猜你喜欢

Vant3 - click on the corresponding name name to jump to the next page corresponding to the location of the name of the TAB bar

typescript48 - type compatibility between functions

idea中diagram使用

2022 China Computing Power Conference released the excellent results of "Innovation Pioneer"

Web APIs BOM- 操作浏览器:swiper 插件

工程制图复习题

5. Scrapy middleware & distributed crawler

快速入门EasyX图形编程

【store商城项目01】环境准备以及测试

nodejs+express实现数据库mysql的访问,并展示数据到页面上
随机推荐
Analysis: What makes the Nomad Bridge hack unique
虚拟机CentOS7中无图形界面安装Oracle
MongoDB数据接入实践
boot issue
boot issue
.NET Static Code Weaving - Rougamo Release 1.1.0
appium软件自动化测试框架
持续投入商品研发,叮咚买菜赢在了供应链投入上
ASP.NET 获取数据库的数据并写入到excel表格中
nodejs+express realizes the access to the database mysql and displays the data on the page
即席查询——Presto
Analysis of usage scenarios of mutex, read-write lock, spin lock, and atomic operation instructions xaddl and cmpxchg
typescript48-函数之间的类型兼容性
观察者模式
typescript51 - basic use of generics
initramfs详解----添加硬盘驱动并访问磁盘
typescript55 - generic constraints
js中常用的几种遍历处理数据的方法梳理
计算首屏时间
VR panorama shooting online exhibition hall, 3D panorama brings you an immersive experience