-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

3
  • 2
    max takes an iterable, you pass it a float. 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? Commented Dec 1, 2017 at 6:59
  • can you post error message here ?/ Commented Dec 1, 2017 at 7:02
  • Max should be passed a tuple. Float given Commented Dec 1, 2017 at 7:12

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

1 Comment

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
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)

3 Comments

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
it is running fine then ? i have checked it by running online and it is giving 1200 as an answer !!
@SerkanKılınç please accept and upvote answer if it solved your problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.