Last answered:

05 Apr 2020

Posted on:

05 Apr 2020

0

Error in python code

count = 0
def towers_of_honoi(A,B,C,n):
global count

if n == 1:
disk = A.pop()
C.append(disk)
count += 1
else:

tower_of_honoi(A,C,B,n-1)
tower_of_honoi(A,B,C,1)
tower_of_honoi(B,A,C,n-1)
return count   error is A not defined
1 answers ( 0 marked as helpful)
Instructor
Posted on:

05 Apr 2020

0
Hi Viraj,  thanks for reaching out! You need to define A, B and C, which represent the towers we want to stack. Try the following code before the def towers_of_hanoi: A = [3,2,1]
B = []
C = []   Best, Eli

Submit an answer