[Hackerrank] Finding the percentage
문제 설명
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.
Output Format
Print one line: The average of the marks obtained by the particular student correct to 2 decimal places.
Others
- 2 $\leq$ n $\leq$ 10
- 0 $\leq$ marks[i] $\leq$ 100
- length of marks arrays = 3
입출력 예
Sample Input 0
3
Krishna 67 68 69
Arjun 70 98 63
Malika 52 56 60
Malika
Sample Output 0
56.00
Idea
백준이랑 프로그래머스 같은 국내사이트들도 훌륭하지만,
영어공부의 필요성을 느껴서, hackerrank site의 문제들을 풀고있다.
순서대로 풀고있어서, 쉬운문제를 풀고있지만, 점점 어려워질것같다!
아래와 같이 풀어보았다..
코드잼도 풀어서 올려야겠다.
Code
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()
select_score = list()
for key, scores in student_marks.items():
if key == query_name:
select_score = scores
print(f"{(sum(select_score) / len(select_score)):.2f}")
Explain
baseline code들을 최대한 안 건드리고 푸는식으로 계속 진행하고 있다.
설명 패스!!
댓글남기기