《笨方法学 Python 3》29.if语句

基础练习:

people = 20
cats = 30
dogs = 15


if people < cats:
	print("Too many cats! The world is doomed!")  '''太多的猫!世界末日到了!'''

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 equal to dogs.")  '''人比狗多'''

if people <= dogs:
	print("People are less than or equal to dogs.")  '''人比狗少'''

if people == dogs:
	print("People are dogs.")   '''人是狗(!?!?!emm)'''

结果:


+=是什么意思???

 可以称为:“递增”运算符,例如:x += 1 就是 x = x + 1

然后还有:

-=,“递减”运算符, x -= 1 就是 x = x - 1

*=, x *= 1 就是 x = x * 1

/=, x /= 1 就是 x = x / 1

应该还有,上面是我瞎猜的,改天百度一下看看对不对...


 Zed的提问:

看下Zed的问题,取了两个问题,其他的懒得写了...

 1.  if 语句对他的下一行做了什么???

做了一个真假判断,判断为真(True)则执行 if 语句下方所有缩进的代码,判定为假(False)则跳过不执行!

2.  把习题27中的其他布尔表达式放到 if 语句中会不会也可以运行呢?试一下。

emm,先待定吧,现在懒得写,以后想起来了补充!

END!!!

猜你喜欢

转载自blog.csdn.net/waitan2018/article/details/82794661