Collections.namedtuple()

Sort by

recency

|

1054 Discussions

|

  • + 0 comments

    Write the code in 4 lines except for import and main statements.

    from collections import namedtuple
    if __name__ == '__main__':
        N, Mark, totalScore = int(input()), namedtuple('Mask', ','.join(input().split())), 0
        
        for _ in range(N):
            totalScore += int(Mark(*input().split()).MARKS)
            
        print(f"{totalScore/N:.2f}")
    
  • + 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))
    
  • + 0 comments
    from collections import namedtuple
    
    N = int(input())
    
    StudentMarks = namedtuple('StudentMarks',input().split())
    
    Marks_list = []
    
    for i in range(N):
        a,b,c,d = input().split()
        S = StudentMarks(a,b,c,d)
        Marks_list.append(int(S.MARKS))
    
    print(round(sum(Marks_list)/len(Marks_list),2))
    
  • + 0 comments

    n = int(input())

    from collections import namedtuple students = namedtuple('students', input())

    sum_notes = 0 for counter in range(n): x, y, z, w = input().split() st = students(x, y, z, w) sum_notes += int(st.MARKS)

    avg_notes = (sum_notes/n) print(f"{avg_notes:.2f}")

  • + 0 comments
    1. from collections import namedtuple
    2. n = int(input())
    3. student = namedtuple('student',input())
    4. marks = 0
    5. for i in range(n):
    6. a,b,c,d = input().split()
    7. stu = student(a,b,c,d)
    8. stu_update = stu._replace(MARKS=int(stu.MARKS))
    9. marks += stu_update.MARKS
    10. print(round((marks/n),2))