I am new to python and I have an assignment, I need to write a recursive function that takes two arguments (Weights, W), weights is the list of weights of baggage and W is the maximal weight a student can take, in python 2.7 that calculates the maximal amount of baggage a student can take and does not pass the maximal limit (W), for example if:
>>> calc_max_baggage([5], 0)
>>> 0
>>> calc_max_baggage ([1, 1, 1], 5)
>>> 3
>>> calc_max_baggage([4, 2, 3, 1], 5)
>>> 2
This is my code but it returns error:
def calc_max_baggage (weights, W):
weights = []
res = []
W = int
def number_of_index(weights, W, i): if max(weights) > W:return reselse:count += i in weightsreturn calc_max_baggage()
Error message:
Traceback (most recent call last):File "", line 1, in calc_max_baggage ([5], 0)File "C:/Users/user/Desktop/לימודים/פייתון Python/עבודות בית/ex6/test_ex6.py", line 12, in calc_max_baggagereturn calc_max_baggage()TypeError: calc_max_baggage() takes exactly 2 arguments (0 given)
I am totally not sure about my code I think its totally wrong
Weights is the list of weights and W is the maximal weight.
Given this, I want to know how many items from the weights[] list can be brought on the plane.
*I can't change the funtion calc_max_baggage(weights, W)
that takes two arguments.
W can also be negative, in that case the function returns 0.
IT MUST BE SOLVED WITH RECURSION ONLY AND WITHOUT LOOPS
Thanks