当前位置:网站首页>006操作符简介
006操作符简介
2022-07-25 14:35:00 【烧不死的菜鸟叫凤凰】
一、思维导图

二、知识与例子
1、a=a+3 等同于a+=3;a=a3等同于a=3
2、“/”真实除法;“//”取整除法
例子:10\3=3.33333;10//3=3
3、平方运算
32=9 代表平方2次
3***5 代表平方5次
4、取余数运算例子:
5%2 代表取余数 结果=1
5、逻辑运算符号的逻辑短路现象
请用最快速度说出答案:not 1 or 0 and 1 or 3 and 4 or 5 and 6 or 7 and 8 and 9
答案:4
原因:在python中,逻辑运算符or,x or y, 如果x为True则返回x,如果x为False返回y值。因为如果x为True那么or运算就不需要在运算了,因为一个为真则为真,所以返回x的值。如果x的值为假,那么or运算的结果取决于y,所以返回y的值。
**在python中,逻辑运算符and,**x and y,如果x为True则返回y值。如果x为False则返回y值。如果x的值为True,and的运算不会结束,会继续看y的值,所以此时真与假取决于y的值,所以x如果为真,则返回y的值。如果x为假,那么and运算就会结束运算过程了,因为有一个为假则and为假,所以返回x的值。
三、课中代码
四、课后习题
1、改进我们的小游戏:当用户输入错误类型的时候,及时提醒用户重新输入,防止程序崩溃。
print('***** i love cjy *****')
a=input('hi,猜猜我昨天晚上睡了几个小时\n')
while a.isdigit ()!=True:
a= input('please input a int number\n')
if int(a)==9:
print('你猜对了,但是我还没有睡够哦')
else:
print('我睡 了多久你不会数数吗?一点都不关心我,大笨蛋!!!笨笨笨笨笨\n' )
print('游戏结束,下次玩点不一样的')
2、写一个程序,判断给定年份是否为闰年。
a=input('please input a year: ')
year=int(a)
if (year%4==0 and year%100!=0) or (year%400==0):
print('this is a leap year ')
else:
print('this is a not a leap year')
3、设置打印1-100的基数
代码:
for i in range(1,101):
if i%2!=0:
print(i)
i+=1
出现过的错误:
在for循环后面忘记使用’:‘了
边栏推荐
- Writing standard of physical quantities and unit symbols
- gson与fastjson
- 【MySQL系列】-索引知多少
- Educational codeforces round 132 (rated for Div. 2) C, d+ac automata
- Go语言创始人从Google离职
- Bond0 script
- spark参数调整调优
- Sunfeng, general manager of Yixun: the company has completed the share reform and is preparing for IPO
- Maya modeling exercise
- Thymeleaf setting disabled
猜你喜欢

IDEA报错 Failed to determine a suitable driver class

Feiwo technology IPO meeting: annual revenue of 1.13 billion Hunan Cultural Tourism and Yuanli investment are shareholders

Save the image with gaussdb (for redis), and the recommended business can easily reduce the cost by 60%

I2C设备驱动程序的层次结构

Matplotlib data visualization three minutes entry, half an hour enchanted?

English语法_不定代词 - other / another

The concept and operation rules of calculus of variations

牛客多校 E G J L

Niuke multi school E G J L

Under the epidemic, the biomedical industry may usher in breakthrough development
随机推荐
The supply chain collaborative management system, a new "engine" of digitalization in machinery manufacturing industry, helps enterprises' refined management to a new level
VS2017大型工厂ERP管理系统源码 工厂通用ERP源码
~4.1 sword finger offer 05. replace spaces
51单片机学习笔记(2)
Paddlenlp's UIE relationship extraction model [executive relationship extraction as an example]
Gson and fastjson
C language and SQL Server database technology
gson与fastjson
Pytorch training code writing skills, dataloader, Einstein logo
Okaleido ecological core equity Oka, all in fusion mining mode
C language and SQL Server database technology
Software testing -- 1. Outline of software testing knowledge
D2. picking carrots (hard version) (one question per day)
Heyuan City launched fire safety themed milk tea to boost fire prevention and control in summer
H5页面input输入框弹起数字键盘,需要支持小数点
Examples of bio, NiO, AIO
实现一个家庭安防与环境监测系统(二)
OverTheWire-Bandit
微信公众号正式环境上线部署,第三方公众平台接入
GameFramework制作游戏(一)