hello guys I'm trying to write code for an optimization problem in python, the problem is I need to heal a person with medicine, medicine1 heals 25 units requires 3 herb A and 2 herb B and medicine2 heals 20 units requires 4 herb A and 1 herb B.I have 25 units of herb A and 10 units of herb B. in the end I want to print the maximum health that I can heal and how many of each medicines 1 and 2 that I used(clearly had no idea how to put it)
I tried to write a knapsack problem but I keep getting the error
TypeError: unsupported operand type(s) for +: 'int' and 'function'
med1= 25
med2= 20
x=25
y=10
health=0
def knapsack(health,med1,med2,x,y):
if x==0 or y==0:
return knapsack
if(med1+knapsack(health+med1,med1,med2,x-3,y-
2)>med2+knapsack(health+med2,med1,med2,x-4,y-1)):
return (med1+knapsack(health+med1,med1,med2,x-3,y-2))
else:
return (med2+knapsack(health+med2,med1,med2,x-4,y-1))
print(knapsack(health,med1,med2,x,y))
Can someone help me. Thanks