I was trying to write a recursive function that returns the collatz sequence of a number, but the code (shown below) doesn't work. How could this be circumvented and why does this happen?
If I write print(x) instead of return x, it can print fine and I can't figure out why it wouldn't be able to return x.
def collatz(x):
if x[-1] == 1:
return x
elif x[-1] % 2 == 0:
collatz(x + [x[-1]/2])
elif x[-1] % 2 == 1:
collatz(x + [3*x[-1] + 1])
collatz(x +...->return collatz(x +...