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