How to program for the tower of hanoi in python.
- def hanoi(disks, source, auxiliary, target):if disks == 1:print('Move disk 1 from peg {} to peg {}.'.format(source, target))returnhanoi(disks - 1, source, target, auxiliary)print('Move disk {} from peg {} to peg {}.'.format(disks, source, target))hanoi(disks - 1, auxiliary, source, target)disks = int(input('Enter number of disks: '))hanoi(disks, 'A', 'B', 'C')
OutPut:-
0 Comments