I have to calculate a equation that have a recursion. But if I am execute the code i get the failure that the Float object is not iterable
my code is:
def v(t, c):
result = []
if t == 0 or c == 0:
return 0
q = v(t - 1, c) - v(t - 1, c - 1)
return max((0.2*(400-q)), (0.6*(400-q)), (1*(1200-q)), (0.85*(1115-q)), (0.87*(1127-q))) + v(t-1,c)
x = v(2, 1) print(x)
What can I do to get the result? Thank you
You are using max(), but args in your function is a tuple (0.85 * (1115 - q)) + (0.87 * (1127 - q)), this is not right
max() needs to be passed more than one argument and in your case only one argument is there which is causing the error. Try removing max or add one more results to your max() function to make it behave correctly.
def v(t, c):
result = []
if t == 0 or c == 0:
return 0
q = v(t - 1, c) - v(t - 1, c - 1)
return ((0.85 * (1115 - q)) + (0.87 * (1127 - q))) + v(t - 1, c)
x = v(2, 1)
print(x)
maxtakes an iterable, you pass it afloat. The error message is quite to the point. What do you want the maximum of there when you pass a single value to the function? - user2390182