if---else

if x= =A:

    do something for A

elif x = = B:

    do something for B

else:

    do something for else

python没有分支结构case, 用多个elif来实现分支。

 

例子:

AGE = 56

guess_age = int( input("oldboy's age:"))

print(type(guess_age))

if guess_age == AGE:

    print("Contratulations..")

elif guess_age < AGE:

    print("try bigger...")

else:

    print("try smaller...")

 

 

 

posted on 2019-11-13 15:13  锋锋2019  阅读(995)  评论(0编辑  收藏  举报

导航