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. 新概念英语(1-53)An interesting climate

    新概念英语(1-53)An interesting  climate What's the favourite subject of conversation in England? A:Where ...

  2. jquery中attr与prop的区别

    先从一个老生常谈的问题说起,使用jquery实现全选全不选.楼主先使用的jquery版本是 jquery-1.11.1.min.js 全选<input type="checkbox&q ...

  3. Linux下wget获取ftp下目录下文件

    如果某个目录下有一个文件可以使用ftp命令: get xxx 如果是某个目录下有多个文件(且不需要获取目录下子文件夹下的内容): mget * 如果是某个目录下有子目录希望获取所有子目录: wget ...

  4. Spring基础复习

    Spring IOC 使用注解实现Bean管理 注解类型: @Component:spring定义的通用注解,可用于注解任何bean @Repository, @Service,@Controller ...

  5. [ZooKeeper] 1 基本概念

    ZooKeeper: A Distributed Coordination Service for Distributed Applications ZooKeeper is a distribute ...

  6. [LeetCode] Minimum Factorization 最小因数分解

    Given a positive integer a, find the smallest positive integer b whose multiplication of each digit ...

  7. Python的基础学习(第二周)

    模块初始 sys模块 import sys sys.path #打印环境变量 sys.argv#打印该文件路径 #注意:该文件名字不能跟导入模块名字相同 os模块 import os cmd_res ...

  8. javascript实现双向数据绑定

    双向数据绑定已经是面试中经常被问到的点,需要对原理和实现都要有一定了解. 下面是实现双向绑定的两种方法: 属性劫持 脏数据检查 一.属性劫持 主要是通过Object对象的defineProperty方 ...

  9. 机器学习技法:09 Decision Tree

    Roadmap Decision Tree Hypothesis Decision Tree Algorithm Decision Tree Heuristics in C&RT Decisi ...

  10. 生成和配置https证书

    最近在做小程序,调用后台接口需要https协议请求,小程序之所以这么要求,也是因为http协议是明文传播文件数据的,出于数据安全考虑,必须使用https协议. http想实现为https 就需要为配置 ...