-
Notifications
You must be signed in to change notification settings - Fork 0
/
Finding the percentage
35 lines (27 loc) · 2.74 KB
/
Finding the percentage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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] quesy_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. 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
____________________________________________________________________________________________
solution for this code is
n = int(input())
student_marks = {}
for _ in range(n):
line = input().split()
name = line[0]
marks = list(map(float, line[1:]))
student_marks[name] = marks
query_name = input()
marks = student_marks[query_name]
average_marks = sum(marks) / len(marks)
print("{:.2f}".format(average_marks))
________________________________________________________________________________________________
you can use this code to pass all test cases