There are three thimbles , On the first thimble were several plates , And the small plate is on the big plate , Now move these plates from the first thimble to the third thimble , And the small plate is still on the big plate . The second thimble can be used during the movement , Only one plate can be moved at a time , And the small plate should be on top of the big plate , How to move all the plates from the first thimble to the third thimble .
Adopt the method of recursive iteration , First, I will n-1 Move the first plate to the second thimble , Move the plate on the first thimble to the ` Three thimbles , In the same way n-1 One plate moves to the third plate .
def hanoni(n,x,y,z):
if(n==1):
print(x,'--->',z);
else:
hanoni(n-1,x,z,y);
print(x,'--->',z);
hanoni(n-1,y,x,z);
n = int(input(' Please enter the number of floors of Hanoi tower :'));
hanoni(n,'x','y','z');