python 中 if elif 和 else 用法

python 中 if elif 和 else 用法

salary = int (input("your salary :"))
if salary <= 1000:
    print("I am your father:")
elif salary <= 2000:
    print("Go out!")
elif salary <= 5000:
    print("The boss is a zz!")
elif salary <= 10000:
    print("When I back home, I will think.,")
elif salary <= 20000:
    print("That is ok!")
elif salary <= 30000:
    print("The boss is right!")
elif salary <= 5000:
    print("996 is ok!")
else:
    print("Firm is my home!")

由上往下判断当其中一个条件满足时,则进入执行,不再执行剩余代码。
else表示最后一个选项,前面都不满足时就执行。

你可能感兴趣的:(python)