python实现汉诺塔(递归)

def hanoi(n, A, B, C):
    if n > 0:
        hanoi(n-1, A, C, B)
        print("%s->%s" % (A, C))
        hanoi(n-1, B, A, C)

hanoi(4, 'A', 'B', 'C')

 

posted @ 2018-12-15 13:32  小学弟-  阅读(959)  评论(0编辑  收藏  举报