I am learning python by solving python module from HackerRank. This problem is Find the Percentage.
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 N integer 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.
Sample Input 0
3 Krishna 67 68 69 Arjun 70 98 63 Malika 52 56 60 Malika
Sample Output 0
56.00
I need to improve this code by using better functions available in python.
def percentage(name):
"""
Find percentage of marks of the student
"""
marks = student_marks[name]
total_marks = 0
for mark in marks:
total_marks += mark
return format(total_marks/len(marks), '.2f')
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()
print(percentage(query_name))