Python Forum

Full Version: "RecursionError: maximum recursion depth exceeded in comparison"
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
def sum_arithmetic(n_terms, start_val, inc_val):
    if n_terms == 0:
        return 0
    else:
        return start_val+ sum_arithmetic((start_val+inc_val), inc_val, (n_terms-1))

print(sum_arithmetic(5,0,1))
How can I fix this error?
Thanks
Don't use recursion?

Even if you fix your error, you still have a limitation on the recursion depth. That is not why the function failed in this case, but it should always be in the back of your mind.

In this particular case you should check the order of the arguments in the recursive function call.

This is a really convoluted way to add up up the numbers from 1 to 4.