HackerRank Python Problem No7 || Dictionary ||reduce function

Veröffentlicht am: 03 September 2021
auf dem Kanal: Bhanu Prathap
3,797
32

We have a record of 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 followed by the names and marks for students. We 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 , the number of students' records. The next 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.

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 whose average is

Sample Input 1

2
Harsh 25 26.5 28
Anurag 26 28 30
Harsh
Sample Output 1

26.50

Alternate 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()
query_score=student_marks[query_name]
a=(sum(query_score)/n)
print("{0:.2f}".format(a))


Auf dieser Seite können Sie das Online-Video HackerRank Python Problem No7 || Dictionary ||reduce function mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Bhanu Prathap 03 September 2021 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 3,797 Mal angesehen und es wurde von 32 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!