popovIliya

Recursion "Hanoi towers"

Mar 14th, 2021
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.31 KB | None | 0 0
  1. def Main():
  2.     n = int(input("Set the number of disks: "))
  3.     a = 'A'
  4.     b = 'B'
  5.     c = 'C'
  6.     Hancula(a, b, c, n)
  7.    
  8. def Hancula(a, b, c, n):
  9.     if(n>0):
  10.             Hancula(a, c, b, n-1)
  11.             print("Move a disk from a pylon",a, "to", c)
  12.             Hancula(b, a, c, n-1)
  13.        
  14. Main()
  15.  
Advertisement
Add Comment
Please, Sign In to add comment