python学习日记_第十二天(ex29~30)

来源:互联网 发布:db2 oracle mysql 编辑:程序博客网 时间:2024/06/07 14:49

L29 如果(If)
If语句的练习:

#coding:utf-8people = 20cats = 30dogs = 15#下面这个用还有not的符合布朗式做判断条件if not (1 == 10 or 3 == 4):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 += 5if 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 对于它下一行的代码做了什么?    判断是否执行。2.为什么 if 语句的下一行需要 4 个空格的缩进?    这个python的格式,用来判断if控制的范围。3.如果不缩进,会发生什么事情?    会报错4.把习题 27 中的其它布尔表达式放到``if语句``中会不会也可以运行呢?试一下。如果把变量 people, cats, 和 dogs 的初始值改掉,会发生什么事情?    可以。更改变量使if条件变化,执行的内容也会变化。'''

L30 Else 和 If

#coding:utf-8people = 30cars = 40buses = 50if cars > people:    print "We should take the cars."elif cars < people:    print "We should not take the cars."else:    print "We can't decide."if buses > cars:    print "That's too many buses."elif buses <cars:    print "Maybe we could take the buses."else:    print "We still can't decide."
0 0
原创粉丝点击