Collections.namedtuple()

Sort by

recency

|

1052 Discussions

|

  • + 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))
  • + 0 comments

    What is healthhubin.com? The platform is dedicated to providing health information. The platform’s content covers wellness practices, helping readers implement positive changes. For more info, click this link https://healthhubin.com/. Its commitment to accuracy ensures that visitors receive guidance for a healthy life.

  • + 0 comments

    from collections import namedtuple

    n = int(input())
    Stu = namedtuple('Student', input())
    print(sum(int(Stu._make(input().split()).MARKS) for _ in range(n)) / n)

    Stu._make(...): The _make method is called on the Stu named tuple, which takes the list of strings and creates a Student instance. For our example, if input is Alice 80, it creates Student(NAME='Alice', MARKS='80').