วันอาทิตย์ที่ 25 ตุลาคม พ.ศ. 2558

Find index of the floor(s) with maximum number of chairs (in the building)

def setup():
   one = [10, 20, 30, 40, 50]
   two = [60, 50, 40, 30, 20]
   three = [10, 80, 50, 20, 90]
   four = [50, 30, 20, 40, 60]
   a = [one, two, three, four]
   find(a)
 
def find(a):
   i = 0
   total = 0
   value = 0
   imax = 0
   while(i < len(a)):
      total = 0
      x = 0
      while(x < len(a[i])):
         total = total + a[i][x]
         x = x +1
      if(total > value):
         value = total
         imax = i
      i = i + 1
   print("Index is",imax)
 
setup()

ไม่มีความคิดเห็น:

แสดงความคิดเห็น