Mar-15-2019, 03:03 AM
(Mar-15-2019, 12:11 AM)micseydel Wrote: You're using recursion. When you have recursion, you have two situations: a "base case" (where you don't recurse) and a recursive case. The error you're encountering is incredibly common when the base case isn't solid. I suggest you not just use Yoriz' code, but rather you walk through your own code and then his in order to understand what's happening.
Also, this looks like homework, which often has weird requirements, but I wouldn't use recursion for what you're trying to do there.
Thank you for your reply. I'm still trying to understand some basic python knowledge. Your answer is very helpful.
I move forward a little bit and came up with another weird problem as below.
def ChangeList(itr, K =[0]): if itr < 10: K.append(1) itr += 1 return ChangeList(K, itr) else: return K for i in range(5): print (ChangeList(i, K = [0]))I was trying to using recursion in a for loop, but it did work as I expected. Could you please show me the right way to do it?