본문 바로가기
프로그램

[파이썬] 문제 : 10명의 학생 점수 입력 받아서 합계,평균 계산

by 오디세이99 2023. 11. 29.
728x90
반응형
# 10명의 학생 점수를 입력받는 2차원 리스트 생성
num_students = 10
scores = []
for _ in range(num_students):
    tmp = input("점수를 입력하세요(예:학생번호,국어,수학,영어): ").split(',')
    for i in range(1,4):
        tmp[i] = int(tmp[i])
    scores.append(tmp)

# 각 학생의 총점과 평균 계산
student_totals = []
for student_scores in scores:
    total = sum(student_scores[1:])
    average = total / len(student_scores[1:])
    student_totals.append((total, average))

# 10명 학생의 평균 점수 계산
avg_total = [total for _ , total in student_totals]    # average값의 총합
average_total = sum(avg_total) / num_students

print(f"10명 학생의 평균 점수: {average_total:.2f}")

728x90
반응형

댓글