HackerRank/해커랭크-Finding the percentage-python

cosmos·2021년 8월 9일
0
post-thumbnail
post-custom-banner

문제

풀이

  • 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.

코드

# HackerRank, Finding the percentage, python3
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)))

결과

출처 && 깃허브

HackerRank
github

post-custom-banner

0개의 댓글