HackerRank Python - Collections.namedtuple()

Basically, namedtuples are easy to create, lightweight object types.
They turn tuples into convenient containers for simple tasks.
With namedtuples, you don’t have to use integer indices for accessing members of a tuple.

  1. # Enter your code here. Read input from STDIN. Print output to STDOUT
  2. from collections import namedtuple
  3. n = int(input())
  4. fields = input().split()
  5. total_marks = 0
  6. for _ in range(n):
  7. students = namedtuple('student', fields)
  8. MARKS, CLASS, NAME, ID = input().split()
  9. student = students(MARKS, CLASS, NAME, ID)
  10. total_marks += int(student.MARKS)
  11. print('{:.2f}'.format(total_marks / n))
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]

donate a cup of tea :)

Join Our Facebook Group

Share this solution


Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube