I have a very simple function in python that I made while using codecademy.com. The code passed the exercise but it does cause a maximum recursion error and I do not understand why. This is what I have:
n = [3, 5, 7]
def double_list(x):
for i in range(0, len(x)):
x[i] = x[i] * 2
return double_list(x)
print double_list(n)
Because in your double_list
you are calling double_list
again?
return double_list(x)
That will cause you to enter the endless loop unless you set a condition in which it should break upon.
OP already solved it, and this is his solution:
n = [3, 5, 7]
def double_list(x):
for i in range(0, len(x)):
x[i] = x[i] * 2
return x
print double_list(n)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With