“笨办法”学Python3,Zed A. Shaw,习题29+30

代码

people = 20
cats = 30
dogs = 15

if 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必定返回false1 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之后跟随一个布尔值相互比较的算式,可以任何复杂程度。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值