import math

n = int(input('Input an integer:'))
m = int(math.sqrt(n) + 1)
for i in range(2, m):
if n % i == 0:
print('No')
break
else:
print('Yes') #输出结果
#Input an integer:23
#Yes

Python小代码_10_判断是否为素数的更多相关文章

  1. Python小代码_2_格式化输出

    Python小代码_2_格式化输出 name = input("name:") age = input("age:") job = input("jo ...

  2. Python小代码_1_九九乘法表

    Python小代码_1_九九乘法表 max_num = 9 row = 1 while row <= max_num: col = 1 while col <= row: print(st ...

  3. Python小代码_6_列表推导式求 100 以内的所有素数

    import math a = [p for p in range(2, 100) if 0 not in [p % d for d in range(2, int(math.sqrt(p)) + 1 ...

  4. Ruby测试小代码[计算50以内的素数]

    算法思想 判断某一个数,能不能被比他平方根小的素数整除. 首先看看代码 $arr = [] $arr[0] = 2 def add_prime(n) 3.step(n,2){|num| $arr &l ...

  5. Python小练习之判断一个日期是一年的第几天

    python练手遇到的一个问题写了个统一公式,不用麻烦的分各种类,如果有人测试出错误请评论通知. #分单双月 def dayNum(month,day,isLeap): if month % 2 != ...

  6. Python小代码_8_今天是今年的第几天

    import time date = time.localtime() print(date) #time.struct_time(tm_year=2018, tm_mon=2, tm_mday=24 ...

  7. Python小代码_4_省市区三级菜单

    menu = { "北京": { "朝阳区": { "三环到四环之间": {}, "四环到五环之间": {}, &quo ...

  8. Python小例子(判断质数)

    只能被自己或者1整除的数为质数 num = int(input('请输入一个数:')) if num > 1: # 查看因子 for i in range(2, num): if (num % ...

  9. Python小代码_14_交换 2 个变量的 3 种方式

    a = 4 b = 5 #第一种 c = a a = b b = c print(a, b) #输出结果 #5 4 #第二种 a = a + b b = a - b a = a - b print(a ...

随机推荐

  1. SpringCloud的服务注册中心(二)注册中心服务端和两个微服务应用客户端

    一.构建EurekaServer工程 1.pom.xml 2.application.yml 3. EurekaServerApp.java 4.启动EurekaServer 二.构建部署 Eurek ...

  2. SpringCloud是什么?

    参考链接: http://blog.csdn.net/forezp/article/details/70148833 一.概念定义       Spring Cloud是一个微服务框架,相比Dubbo ...

  3. 命名参数名(含*args , * *kw的区别)

    要限制关键字参数的名字,就可以用命名关键字参数 # coding=utf-8 # 命名关键字参数需要一个特殊分隔符*,*后面的参数被视为命名关键字参数.调用方式如下 def person(name, ...

  4. 如何使用Visual Studio 2017自带的源代码反编译功能

    反编译C#源代码,大家可能第一时间想到 .NET Reflector 这个工具.但是这个工具反编译出来的代码跟实际源码还是有一定差距的,阅读起来不是很便利. 本人在查看Visual Studio 20 ...

  5. SpringMVC(四):@RequestMapping结合org.springframework.web.filter.HiddenHttpMethodFilter实现REST请求

    1)REST具体表现: --- /account/1  HTTP GET       获取id=1的account --- /account/1  HTTP DELETE 删除id=1的account ...

  6. Vue mint ui用在消息页面上拉加载下拉刷新loadmore 标记

    之前总结过一个页面存在多个下拉加载的处理方式,今天再来说一下在消息页面的上拉加载和下拉刷新,基本上每个app都会有消息页面,会遇到这个需求 需求:每次加载十条数据,上拉加载下拉刷新,并且没有点击查看过 ...

  7. YII2框架下使用PHPExcel导出柱状图

    导出结果: 首先,到官网下载PHPExcel插件包,下载后文件夹如下: 将Classes文件夹放入到项目公共方法内. 新建控制器(访问导出的方法):EntryandexitController < ...

  8. 持久化 XSS:ServiceWorkers 利用

    来源:http://www.mottoin.com/95058.html 来源:https://www.owasp.org/images/3/35/2017-04-20-JSONPXSS.pdf Se ...

  9. phpcmsV9.5.8 后台拿shell

    参考url:https://xianzhi.aliyun.com/forum/read/1507.html poc:index.php??m=content&c=content&a=p ...

  10. XMLHTTPRequestObject获取服务器数据

    http://www.educity.cn/develop/526316.html 在Web客户端使用xmlhttp对象,可以十分方便的和服务器交换数据,我们可以获取和发送任何类型的数据,甚至二进制数 ...