列表列表区域
Area of Lists of Lists
一直想弄清楚如何完成此操作,但无济于事
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
def area(h):
total_area = 0
for room in h:
total_area += room[0] * room[1]
return total_area
一直想弄清楚如何完成此操作,但无济于事
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
def area(h):
total_area = 0
for room in h:
total_area += room[0] * room[1]
return total_area