python汉诺塔问题

def hannuo(n,a,b,c):
    if n == 1:
        print(a,"->",c)
    else:
        hannuo(n-1,a,c,b)#将最后一个盘子移到c
        print(a,"->",c)#将剩余的盘子移动c 
        hannuo(n-1,b,a,c)
n = int(input())
hannuo(n,"A","B","C")

 

posted @ 2020-03-31 23:08  VVsin  阅读(212)  评论(0)    收藏  举报