
# bagWeights.py
# input: 10 or 12

def select(i, maxW, ws):
  if i == -1 or maxW <= 0:
    return 0
  elif ws[i] > maxW:
    return select(i-1, maxW, ws)
  else:
    return max( select(i-1, maxW, ws), 
                ws[i] + select(i-1, maxW-ws[i], ws))
    

# ----- main -----
ws = [3, 4.9, 7.2, 12.1, 4, 1]
print(ws)
maxW = float(input("Enter the weight limit for the bag: "))

print("The maximum weight of the items placed in the bag is",
  select(len(ws) - 1, maxW, ws))
