编写python程序,用户输入一系列成绩,输入-1时结束,输出一共输入了几组数据,最高成绩,最低成绩,平均成绩,不同区间成绩的人数
时间: 2024-05-29 21:11:23 浏览: 12
scores = []
while True:
score = input("请输入成绩,输入-1结束:")
if score == "-1":
break
scores.append(int(score))
num_scores = len(scores)
max_score = max(scores)
min_score = min(scores)
avg_score = sum(scores) / num_scores
# 统计不同区间成绩的人数
interval_dict = {"[0, 60)": 0, "[60, 70)": 0, "[70, 80)": 0, "[80, 90)": 0, "[90, 100]": 0}
for score in scores:
if score < 60:
interval_dict["[0, 60)"] += 1
elif score < 70:
interval_dict["[60, 70)"] += 1
elif score < 80:
interval_dict["[70, 80)"] += 1
elif score < 90:
interval_dict["[80, 90)"] += 1
else:
interval_dict["[90, 100]"] += 1
print("一共输入了 %d 组数据" % num_scores)
print("最高成绩是 %d" % max_score)
print("最低成绩是 %d" % min_score)
print("平均成绩是 %.2f" % avg_score)
print("不同区间成绩的人数如下:")
for interval, num in interval_dict.items():
print("%s : %d" % (interval, num))
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![.zip](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)