Hi I'm new to Python and I have this list of list:
product_list=[[0, 'Cool Blue Marella Jug', 33, 15], [1, 'Weight Loss Pack', 55, 16], [2, 'Weight Loss Pack', 10, 16]]
and the first number is basically the index, the second number(33,55,10) is the price and the third number(15,16,16) is the profit. Given a price limit of say 15 my code should print the max profit which is obviously 16 in this case. But it prints 32 instead?
This is my code:
def dp_pricelimit(product_list, price_limit):
memo=[0]*(price_limit +1)
memo[0]=0
for price in range(1, price_limit +1):
for item in product_list:#go through the items
if item[2]<=price_limit:
balance=price_limit-item[2]
profit=item[3] + memo[balance]
if profit>memo[price]:#if found new optimal
memo[price]=profit
return memo[price_limit]
Any help will be appreciated. Thanks!