Discuss / Python / 111

L0standfound

#1 Created at ... [Delete] [Delete and Lock User]

还是有点模糊 参考了百度百科下面的python代码才看懂

def move(n, a, b, c): if n == 1: print(a, '-->', c) else: move(n-1, a, c, b)#将前n-1个盘子从a移动到b上 move(1, a, b, c)#将最底下的最后一个盘子从a移动到c上 move(n-1, b, a, c)#将b上的n-1个盘子移动到c上 n = input('enter the number:') move(int(n), 'A', 'B', 'C')


  • 1

Reply