编写float fun,统计出若干个学生的平均成绩,最高分以及得最高分的人数
时间: 2023-06-09 20:03:56 浏览: 64
好的,以下是编写float fun的代码:
```python
def float_fun(scores):
"""
计算平均成绩和最高分及得最高分的人数
:param scores: 学生的成绩,为一个列表
:return: 一个元组,第一个元素是平均成绩,第二个元素是最高分,第三个元素是得最高分的人数
"""
# 如果列表为空,返回None
if not scores:
return None
total_score = 0 # 总分
highest_score = 0 # 最高分
highest_count = 0 # 得最高分的人数
for score in scores:
total_score += score
if score > highest_score:
highest_score = score
highest_count = 1
elif score == highest_score:
highest_count += 1
avg_score = total_score / len(scores) # 平均成绩
return avg_score, highest_score, highest_count
```
使用方法:
```python
scores = [78, 89, 94, 67, 92, 89, 78, 90, 92, 95]
avg_score, highest_score, highest_count = float_fun(scores)
print("平均成绩:%.2f" % avg_score)
print("最高分:%d" % highest_score)
print("得最高分的人数:%d" % highest_count)
```
输出:
```
平均成绩:86.40
最高分:95
得最高分的人数:1
```