这是我自己学习的答案,会尽力写的比较好。还望大家能够提出我的不足和错误,谢谢!
文中例题:
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 or equal to dogs."
if people <= dogs:
print "People are less than or equal to dogs."
if people == dogs:
print "People are dogs."
运行结果:
习题答案:
1、if 就是在进入其内部语句前对其右边语句进行一次判断,ture 就进入,false 就跳过。
2、if 下一行已经是其内部的语句了
3、不缩进就会报错,因为if后面跟了 : 。跟了 : 下一行就要缩进,表示内部的语句。
5、把初值去掉,就会报错说没定义。python中的变量必须赋值,python中赋值就是声明。