python笔记 多路分支

冷读术?
很多分支的情况,简称多路分支
if 条件表达式 :
语句1
……
elif 条件表达式:
语句1
……
elif 条件表达式:
语句1
……
……
else:
语句1
……
elif 可以有很多个
else可以没有,可选
多路分支只会选一个执行

# score 存放学生成绩
# 注意input的返回值类型
score = input("请输入学生成绩:")
#需要把str转换成int
score = int(score)

if score>90:
    print("a")
elif score>= 80:
    print("b")
elif score>=70:
    print("c")
elif score>=60:
    print("d")
else:
    print("e")

这种语句在执行下一句语句的时候会屏蔽掉上方的条件
if语句可以嵌套使用,但不推荐
python中没有switch-case语句

猜你喜欢

转载自blog.csdn.net/ykallan/article/details/84555237