用python 编写程序:要求键入课程名称及成绩,用空格分割,每门课程一行,遇空行按Enter键结束录入,最后显示最高分和最低分,平均分
时间: 2023-07-29 22:14:33 浏览: 54
以下是一个可能的实现:
```python
scores = []
while True:
line = input()
if not line:
break
name, score = line.split()
score = float(score)
scores.append((name, score))
if not scores:
print("No scores entered")
else:
max_score = max(scores, key=lambda x: x[1])[1]
min_score = min(scores, key=lambda x: x[1])[1]
avg_score = sum(x[1] for x in scores) / len(scores)
print("Max score:", max_score)
print("Min score:", min_score)
print("Avg score:", avg_score)
```
使用时,每输入一行格式为`课程名称 成绩`,以空格分隔。当输入空行时,程序会停止录入,并输出最高分、最低分和平均分。如果没有输入任何分数,则会输出`No scores entered`。