用Python 设计能够循环使用,按分数等级区间划分等级,当输入不符合区间要求的分数时能提示“输入不合要求”,输入“end”输出“该程序结束”
时间: 2023-09-29 09:06:41 浏览: 31
好的,您可以参考以下代码实现:
```python
while True:
score = input("请输入分数:")
if score == "end":
print("该程序结束")
break
score = int(score)
if score >= 90 and score <= 100:
print("该生的等级为A")
elif score >= 80 and score < 90:
print("该生的等级为B")
elif score >= 70 and score < 80:
print("该生的等级为C")
elif score >= 60 and score < 70:
print("该生的等级为D")
elif score >= 0 and score < 60:
print("该生的等级为E")
else:
print("输入不合要求,请重新输入")
```
这段代码会循环不断地等待用户输入分数,当用户输入"end"时,程序会结束。当用户输入一个整数分数时,程序会根据分数等级划分规则输出该生的等级。如果用户输入的不是整数分数,则会提示输入不合要求,让用户重新输入。