'''
多分支结构:多选一执行
练习:从键盘录入一个整数 成绩
90-100 A
80-89 B
70-79 C
60-69 D
0-59 E
小于0或者大于100 为非法数据(不是成绩的有限范围)
'''
score =int(input("请输入一个成绩:"))if score >=90and score <=100:# 也可以写为:if 90 <= score <= 100:print("A级")elif80<= score <=89:# 也可以写为:if score >= 80 and score <= 89:print("B级")elif70<= score <=79:print("C级")elif60<= score <=69:print("D级")elif0<= score <=59:print("E级")else:print("输入的成绩为非法数据!")
运行结果:
D:\Environment\Python\Python311\python.exe D:\Environment\PythonWorks\learnpython\马士兵Python\第4章_往哪走呢\32_31.分支结构_多分支结构.py
请输入一个成绩:98
A级
Process finished with exit code 0