In this HackerRank Finding, the percentage in python problem we have given 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.
HackerRank Finding the percentage in python problem solution
# Enter your code here. Read input from STDIN. Print output to STDOUT
test_case = int(raw_input())
list_students = {}
if __name__ == '__main__':
for i in range(test_case):
name_and_points = raw_input().rstrip('\n')
name = name_and_points.split(' ')[0]
points = map(float, name_and_points.split(' ')[1:])
list_students.update({name:points})
name_to_check = raw_input().rstrip('\n')
points_to_check = list_students[name_to_check]
print format(reduce(lambda x,y: x+y, points_to_check)/len(points_to_check), '.2f')
Second solution
num = int(input())
d = {}
for i in range(num) :
line = input().split()
d[line[0]] = list(map(float, line[1:]))
name = input()
sum = sum(d[name])
sum = sum/(len(d[name]))
print("%.2f" % sum)
1 Comments
bro how to learn datascience please send me link in mail bro
ReplyDeleteanilkumarp0708@gmail.com