HackerRank - Finding the percentage solution
1 min read

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 

Enjoying these posts? Subscribe for more

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

That's okay. But without advertising-income, we can't keep making this site awesome.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add thepoorcoder.com to your ad blocking whitelist or disable your adblocking software.