python学习笔记_day6(ex29-31:判断)

小结 ex29-31:判断

ex29:如果(if)
概念:区段

if people < 3:
    print "Too many cats! The world is doomed!"

为什么if语句的下一行需要4个空格的缩进?
如果不缩进,会报错:expected an indented block

ex30:习题 30: Else 和 If

if x > y:
	语块1
elif x < y:
	语块2
else:
	语块3

ex31:作出决定
if语句的嵌套

...
if door == "1":

    x= input("> ")
    if x== "1":
       语块
    elif x== "2":
       语块
    else:
       语块

elif door == "2":

    y= input("> ")
    if y== "1" or y== "2":
       语块
    else:
      语块
else:
	语块
...

猜你喜欢

转载自blog.csdn.net/xingxing_sun/article/details/87935711
今日推荐