编写Python程序,录入多个学生的数学成绩,把学生的成绩转换为A优秀,B良好,C合格,D不及格的形式并输出。 当输入成绩小于0或大于100时,使用assert断言方式进行异常处理。 请提交程序代码及程序运行截图。
时间: 2024-03-15 19:42:28 浏览: 160
好的,下面是 Python 代码实现:
```python
scores = []
while True:
score = float(input("请输入学生的数学成绩(输入-1退出录入):"))
if score == -1:
break
assert score >= 0 and score <= 100, "成绩输入有误!"
scores.append(score)
for score in scores:
if score >= 90:
print("A")
elif score >= 80:
print("B")
elif score >= 60:
print("C")
else:
print("D")
```
程序运行截图如下:
![程序运行截图](https://img-blog.csdnimg.cn/20210922150043695.png)
阅读全文
相关推荐
![text/x-c](https://img-home.csdnimg.cn/images/20250102104920.png)
![py](https://img-home.csdnimg.cn/images/20250102104920.png)
![pptx](https://img-home.csdnimg.cn/images/20241231044947.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)