HackerRank - Finding the percentage solution

HackerRank - Finding the percentage solution

You have a record of N students. Each record contains the student's name, and their percent marks in Maths, Physics and Chemistry. The marks can be floating values. The user enters some integer N followed by the names and marks for N students. You are required to save the record in a dictionary data type. The user then enters a student's name. Output the average percentage marks obtained by that student, correct to two decimal places.

Input Format

The first line contains the integer N, the number of students. The next N lines contains the name and marks obtained by that student separated by a space. The final line contains the name of a particular student previously listed.


  • 2 <= N <= 10
  • 0 <= Marks <= 100

Output Format

Print one line: The average of the marks obtained by the particular student correct to 2 decimal places.

Sample Input 0


Krishna 67 68 69

Arjun 70 98 63

Malika 52 56 60


Sample Output 0


Explanation 0

Marks for Malika are {52,56,60} whose average is (52+56+60)/3 = 36

Sample Input 1


Harsh 25 26.5 28

Anurag 26 28 30


Sample Output 1


Solution in Python3

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()
total_marks = sum(student_marks[query_name])
average_marks = total_marks/3 

Subscribe to The Poor Coder | Algorithm Solutions

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]