“笨办法”学Python3,Zed A. Shaw,习题29+30
习题29
- 代码
- 问题
- 学到的
代码
people = 20
cats = 30
dogs = 15if people < cats:#同“def”一样,用“:”表示一个程序块。print ("Too many cats! The world is doomed!")# 同“def”一样,用开头缩进4个来表示这是一个程序块。if people > cats:print ("Not many cats! The world is saved!")if people < dogs:print ("The world is drooled on!")if people > dogs:print ("The world is dry!")dogs += 5 #"+="意为递增if people >= dogs:print ("People are greater than or equal to dogs.")if people <= dogs:print ("People are less than or equal to dogs.")if people == dogs:print ("People are dogs.")if people == dogs or dogs < cats:print ('I\'m end now.')if people == dogs:print (1)
elif People < dogs:print (2)#30题的内容,因为太简单就和26放一起了。虽然“if条件”简单,但是想完成还是要事事关心,多学多看。1 and false #有false必定返回false;
1 and 2 #没有false返回后面一个值,2
2 and 1 #没有false返回后面一个值,1
# or没什么分的,优先显示非false,其他元素优先级一样,显示方式为显示前面一个元素。
问题
1、or 运算:有True,返回true;无True,返回情况如何呢?
2、and 运算:有False,返回false,无Flase,返回情况如何呢?
学到的
1、if 函数应该是很多地方都有用到的比较简单的函数,判断就离不开if。
2、if之后跟随一个布尔值相互比较的算式,可以任何复杂程度。
“笨办法”学Python3,Zed A. Shaw,习题29+30相关推荐
- 笨办法学python3.6 pdf_“笨办法”学Python3.pdf
作 者 :(美)泽德 A.肖(Zed A. Shaw)著 出版发行 : 北京:人民邮电出版社 , 2018.06 ISBN号 :978-7-115-47881-8 页 数 : 255 原书定价 : 3 ...
- “笨办法”学Python3——练习5 更多变量和打印
** 练习5 源代码 ** 1 my_name = 'Zed A. Shaw' #姓名变量 2 my_age = 35 # not a lie #年龄变量 3 my_height = 74 # inc ...
- “笨办法”学Python3,Zed A. Shaw,习题18
习题18 代码 遇到问题 学到的 代码 # this one is like your scripts with argv def print_two(*args):arg1, arg2 = args ...
- “笨办法”学Python3,Zed A. Shaw, 习题7
习题7 代码 遇到问题 学到的 代码 print("mary had a little lamb.") #用法1 n = "snow" x = f"I ...
- “笨办法”学Python3,Zed A. Shaw,习题21
习题21 代码 遇到问题 学到的 代码 def add(a, b):print(f"ADDING {a} + {b}")return a + bdef subtract(a, b) ...
- “笨办法”学Python3,Zed A. Shaw,习题15
习题15 代码 遇到问题 学到的 代码 from sys import argvscript, filename = argvtxt = open(filename) #txt = filename. ...
- “笨办法”学Python3,Zed A. Shaw,习题20
习题20 代码 遇到问题 学到的 代码 from sys import argv script, input_file = argv def print_all(f):print(f.read())# ...
- “笨办法”学Python3,Zed A. Shaw, 习题3
习题3 代码 遇到问题 学到的 代码 #算术运算 print("1 - 1+2=",1+2) print("2 - 1-2=",1-2) print(" ...
- “笨办法”学Python3,Zed A. Shaw, 习题11
习题11 代码 遇到问题 学到的 代码 print("How old are you?", end = " ") age = input("input ...
最新文章
- 在内部循环中Continue外部循环
- Tengine 安装和基本使用
- jquery文本折叠
- S3C2440的LCD编程
- 【多视图几何】TUM 课程 第2章 刚体运动
- 慎用ArrayList的contains方法,使用HashSet的contains方法代替
- C++11/14::右值引用
- 首次面试凭借Java面试通关宝典,成功逆袭拿下美团offer
- 软文成功案例,给企业带来的价值不可限量
- linux中用来保存组账户的文件,Linux账户管理的几个文件
- 读《浪潮之巅(上)》有感
- 智能运维 | 六度亮剑SREcon,百度引领智能运维新风向
- wmv文件不能快进的解决方法
- 机房收费系统_刷卡充值功能的实现
- 戴尔 成铭3980台式计算机,戴尔成铭3980台式机电脑适合家用吗?-dell成铭3980改win7,dell3980改win7bios设置...
- NVMe系列专题之二:队列(Queue)管理
- CE认证CLASS A和CLASS B的区别
- MicrosoftWPS
- 基于51单片机的超声波测距模块
- PDF文件增加图片水印(盖章)