values = [ 4, 7, 10, 5, 3]
maxVal = max(values)
print (maxVal)
inMaxVal = values.index(maxVal)
print (inMaxVal)
print (values[2])
weights = [15, 8, 2, 6, 12 ]
print (f'item: {inMaxVal+1} weight: {weights[inMaxVal]}')
values = [ 4, 7, 10, 5, 3]
inMaxVal = values.index(max(values))
weights = [15, 8, 2, 6, 12 ]
print (f'item: {inMaxVal+1} weight: {weights[inMaxVal]}')
for item in range(len(weights)):
itemValue = max(values)
maxIndex = values.index(itemValue)
itemWeight = weights[maxIndex]
print (f"Choose item number {maxIndex+1} with index {maxIndex}, value = {itemValue} and weight = {itemWeight}")
values[maxIndex]=0
#
# set value to zero so we don't find it again
values = [ 4, 7, 10, 5, 3] # we need to reload these lists because we modified them
weights = [15, 8, 2, 6, 12 ] # in loop above
backWeight = 0
for item in range(len(weights)):
itemValue = max(values)
maxIndex = values.index(itemValue)
itemWeight = weights[maxIndex]
print (f"Choose item number {maxIndex+1} with index {maxIndex}, value = {itemValue} and weight = {itemWeight}")
backWeight += itemWeight
print (backWeight)
values[maxIndex]=0