汉诺塔(hanoi)

汉诺塔代码:

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')

 

posted @ 2018-12-12 23:39  alittlecomputer  阅读(450)  评论(0编辑  收藏  举报