문제
![](https://velog.velcdn.com/images%2Fcosmos%2Fpost%2Fd61efc2e-ee00-4db6-98d4-136b8d196888%2F%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202021-08-10%20%E1%84%8B%E1%85%A9%E1%84%8C%E1%85%A5%E1%86%AB%2012.04.31.png)
풀이
- The provided code stub will read in a dictionary containing key/value pairs of name:[marks] for a list of students. Print the average of the marks array for the student name provided, showing 2 places after the decimal.
- Input Format : The first line contains the integer n, the number of students' records. The next n lines contain the names and marks obtained by a student, each value separated by a space. The final line contains query_name, the name of a student to query.
- Print one line: The average of the marks obtained by the particular student correct to 2 decimal places.
코드
def solve(query, student):
return sum(student[query]) / len(student[query])
if __name__ == '__main__':
n = int(input())
student_marks = {}
for _ in range(n):
name, *line = input().split()
scores = list(map(float, line))
student_marks[name] = scores
query_name = input()
print("{:.2f}".format(solve(query_name, student_marks)))
결과
![](https://velog.velcdn.com/images%2Fcosmos%2Fpost%2F4bd8fc17-0003-4957-b408-f6eb9b5d200f%2F%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202021-08-10%20%E1%84%8B%E1%85%A9%E1%84%8C%E1%85%A5%E1%86%AB%2012.16.51.png)
출처 && 깃허브
HackerRank
github