# Tower of hanoi by python

__ tower of hanoi :-__

## Rule:-

The problem is to move all the disk from source to destination by the help of Via . A few rules to be followed for Tower of Hanoi are −

- 1) Only one disk can be moved among the towers at any given time.
- 2) Only the “top” disk can be removed.
- 3) No large disk can sit over a small disk.

__Code:-__

#function for tower of hanoi

def TOH(n,a,b,c):

if n==1:

print(a,“to”,c)

else:

TOH(n-1,a,c,b)

TOH(1,a,b,c)

TOH(n-1,b,a,c)

n=int(input(“Enter number of diskn”));

TOH(n,“A”,“B”,“C”)

__Output:-__

Enter number of disk

3

A to C

A to B

C to B

A to C

B to A

B to C

A to C

Excellent

Excellent

Very nice 😊

Good