We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e2b21a5 commit ae21035Copy full SHA for ae21035
1 file changed
Collections/Collectionsnamedtuple.py
@@ -4,14 +4,18 @@
4
Domain : Python
5
Author : Ahmedur Rahman Shovon
6
Created : 15 July 2016
7
+Updated : 09 February 2023
8
Problem : https://www.hackerrank.com/challenges/py-collections-namedtuple/problem
9
"""
10
-n = int(input())
11
-col_list = list(input().split())
12
-marks_col = col_list.index("MARKS")
13
-marks_list = []
14
-for _ in range(n):
15
- info_list = list(input().split())
16
- marks_list.append(float(info_list[marks_col]))
17
-print(sum(marks_list) / n)
+from collections import namedtuple
+n=int(input())
+columns = ",".join(input().split())
+Student = namedtuple("Student", columns)
+data = []
+for i in range(n):
+ row = input().split()
18
+ s = Student._make(row)
19
+ data.append(s)
20
+avg = sum(float(s.MARKS) for s in data) / n
21
+print(f"{avg:.2f}")
0 commit comments