Python Forum
"RecursionError: maximum recursion depth exceeded in comparison"
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"RecursionError: maximum recursion depth exceeded in comparison"
#1
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
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  GCF function w recursion and helper function(how do i fix this Recursion Error) hhydration 3 2,556 Oct-05-2020, 07:47 PM
Last Post: deanhystad
  Increasing depth in python malling 19 14,045 Oct-20-2016, 10:43 PM
Last Post: malling

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020