汉诺塔代码:
def hanoi(n,x,y,z): if n == 1: print(x,‘-->‘,z) else: hanoi(n-1,x,z,y) print(x,‘-->‘,z) hanoi(n-1,y,x,z) n = int(input(‘Input your number:‘)) hanoi(n,‘X‘,‘Y‘,‘Z‘)
原文地址:https://www.cnblogs.com/LoganChen/p/10111715.html
时间: 2024-10-10 20:47:51