Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. pricesPack = [[3.5, 375, 1], [2.5, 300, 2], [2, 100, 3], [3, 225, 4], [1, 50, 5],
  2.              [1.75, 125, 6], [0.75, 75, 7], [3, 275, 8], [2.5, 150, 9], [2.25, 50, 10]]
  3.  
  4. maxWeight = int(input("Maximalgewicht [kg]: "))
  5.  
  6. def createRatioList(listOriginal):
  7.     priceListRatio = []
  8.     for x in range(0, len(listOriginal), 1):
  9.         priceListRatio.append((listOriginal[x][1]/listOriginal[x][0]))
  10.     priceListRatio.sort(reverse = True)
  11.     return priceListRatio
  12.  
  13. def createFinalList(listSorted, listOriginal):
  14.     priceListFinal = []
  15.     pricePackFinal = []
  16.     currentWeight = 0
  17.     for x in range(0, len(listSorted), 1):
  18.         for y in range(0, len(listSorted), 1):
  19.             if listSorted[x] == (listOriginal[y][1]/listOriginal[y][0]):
  20.                 priceListFinal.append(listOriginal[y])
  21.     for x in range(0, len(priceListFinal), 1):
  22.         if (currentWeight + priceListFinal[x][0]) <= maxWeight:
  23.             currentWeight += priceListFinal[x][0]
  24.             pricePackFinal.append(priceListFinal[x][2])
  25.     return pricePackFinal, currentWeight
  26.  
  27. print(createFinalList(createRatioList(pricesPack), pricesPack))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement