Python 编程:找出学习小状元 - 计算总分、最高分和最低分
def find_top_student(scores):
max_score = 0
top_student = ""
for student, score in scores.items():
total_score = sum(score)
if total_score > max_score:
max_score = total_score
top_student = student
return top_student
def find_min_max_score(scores):
all_scores = []
for score in scores.values():
all_scores.extend(score)
min_score = min(all_scores)
max_score = max(all_scores)
return min_score, max_score
N = int(input())
scores = {}
for _ in range(N):
student = input().split()
name = student[0]
student_scores = list(map(int, student[1:]))
scores[name] = student_scores
for student, score in scores.items():
total_score = sum(score)
print(total_score)
top_student = find_top_student(scores)
print(top_student)
min_score, max_score = find_min_max_score(scores)
print(f"{max_score} {min_score}")
原文地址: http://www.cveoy.top/t/topic/pFs7 著作权归作者所有。请勿转载和采集!