a=[1,2,3,4,5]
b=[1,2,3,4,5,5,5,5,5,55,5,5,5,5,5,5,5,5,5,5,5,5,5,5]
def func(a,b):
for i in range(5):
if a[i]>3:
print(len(b))
b.pop()
if not b:
print("cc")
return "tt"
func(a,b)
if len(b)==2:
return "l"
return "t"
print(func(a,b))
The output I got for len(b) is like this. Why the tt is not output and generate an error for empty list? 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 cc 0
def hanoi(n,x,y,z):
if n == 1:
z.append(x.pop())
return
else:
hanoi(n-1,x,z,y)
hanoi(1,x,y,z)
hanoi(n-1,y,x,z)
hanoi(len(A),A,B,C)
I saw hanoi tower code to modify mine. I'm wondering where is the differences without return? Why my code cannot stop but hanoi problem code can stop as soon as reaching the end?
return func(a, b).ctrl-k) ... Discourage screenshots of code and/or errors