Collections.namedtuple()

  • + 0 comments
    from collections import namedtuple
    #take in the input
    people = [input().split() for i in range(int(input())+1)]
    heading = ''
    #to get the second parameter in the namedtuple
    for i in people[0]:
        heading=heading + i +' '
    
    total = 0
    #defining the named_tuple
    students = namedtuple('students', heading)
    
    #calculating the total
    for i in range(1, len(people)):
        temp_tuple = students(people[i][0],people[i][1], people[i][2], people[i][3])
        total = total+ int(temp_tuple.MARKS)
    to_divide = len(people)-1
    #printing out the average
    print(float(total/to_divide))