Search code examples
pythonarea

Area of Lists of Lists


Been trying to figure out how to complete this operation with no avail

Each item in this list is a pair of numbers that represent the dimensions of rooms in a house:

h = [ [18,12], [14,11], [8,10], [8,10] ]

Write a function named area that computes the total area of all rooms, for example:

> area(h)
530

Solution

  • def area(h):
      total_area = 0
      for room in h:
        total_area += room[0] * room[1]
      return total_area