PYTHON BASIC PROBLEMS SOLUTIONS(HACKERRANK) Day-14 LEARN CODING EASILY. HOW TO BE GOOD PROGRAMMER?

Опубликовано: 05 Май 2026
на канале: TECHPARK
53
2

Hello, Young Coders our channel will give you Hackerrank solutions.It will be very useful for you Kindly make use of it..

PROBLEM LINK:https://www.hackerrank.com/challenges...


PROBLEM:

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.

EXAMPLE:

marks key : value pairs are

'alpha' : [20,30,40]

'beta' :[30,50,70]

query_name='beta'

The query_name is 'beta'. beta's average score is .
(30+ 50+ 70)/3 = 50.0

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.

CONSTRAINTS:

1. n value is 2 to 10
2.length of marks arrays=3

OUTPUT FORMAT:

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

SAMPLE INPUT 0:

3
Krishna 67 68 69
Arjun 70 98 63
Malika 52 56 60
Malika

SAMPLE OUTPUT 0:

56.00

EXPLANATION 0:

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

SAMPLE INPUT 0:

2
Harsh 25 26.5 28
Anurag 26 28 30
Harsh

SAMPLE OUTPUT 1:

26.50

SOLUTION:

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()
for i in student_marks:
if i == query_name:
add=sum(student_marks[query_name])
output=add/3
output2=format(output,'.2f')
print(output2)

:) THANKS FOR WATCHING THIS VIDEO :)