-3

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

2 Answers2

0

You are using max(), but args in your function is a tuple (0.85 * (1115 - q)) + (0.87 * (1127 - q)), this is not right

  • in reality my code is: 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) i delete a part of the code to make it easier to understand – Serkan Kılınç Dec 01 '17 at 07:44
0

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)
piet.t
  • 11,718
  • 21
  • 43
  • 52
Akshay Tilekar
  • 1,910
  • 2
  • 12
  • 22