From 7570eced57a41098ec8d16b374faf493c13cdc64 Mon Sep 17 00:00:00 2001 From: Rohanrbharadwaj <89947037+Rohanrbharadwaj@users.noreply.github.com> Date: Sun, 10 Oct 2021 01:49:30 +0530 Subject: [PATCH] Create Tower_of_Hanoi.py --- Python/Tower_of_Hanoi.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Python/Tower_of_Hanoi.py diff --git a/Python/Tower_of_Hanoi.py b/Python/Tower_of_Hanoi.py new file mode 100644 index 00000000..ff72cfa7 --- /dev/null +++ b/Python/Tower_of_Hanoi.py @@ -0,0 +1,11 @@ +def tower_of_hanoi(n, source, destination, auxiliary): + if(n==1): + print("Move disc #1 from source", source, "from to destination", destination) + else: + tower_of_hanoi(n-1, source, auxiliary, destination) + print("Move disc", n, "from source", source,"from to destination", destination) + tower_of_hanoi(n-1, auxiliary, destination, source) + +n_disks=int(input("Enter the number of disks\n")) + +tower_of_hanoi(n_disks, "A", "C", "B")