-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTowerOfHanoi.py
More file actions
27 lines (21 loc) · 767 Bytes
/
TowerOfHanoi.py
File metadata and controls
27 lines (21 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
###########################
# Author: Hemant Tripathi #
###########################
def htower(disks, fromTower, toTower, auxTower):
if disks == 1:
print("Move Disk " + str(disks) + " from Tower" + fromTower + " to Tower" + toTower)
return
else:
htower(disks-1, fromTower, auxTower, toTower)
print("Move Disk " + str(disks) + " from Tower" + fromTower + " to Tower" + toTower)
htower(disks-1, auxTower, toTower, fromTower)
def main():
disks = input("Enter total number of disks less than 10: ");
if int(disks) < int(1):
print('Invalid Input')
elif int(disks) > int(10):
print('Memory Overflow')
else:
htower(int(disks), 'A', 'B', 'C')
if __name__ == "__main__":
main()