danny

Python实现汉诺塔步骤计算
暂时无可提供的摘要
扫描右侧二维码阅读全文
18
2019/12

Python实现汉诺塔步骤计算

   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('请输入汉诺塔的层数:'))
    hanoi(n,'X','Y','Z')
Last modification:December 18th, 2019 at 08:22 pm
If you think my article is useful to you, please feel free to appreciate

One comment

  1. 鳄鱼皮具

    有写怀念学习的日子,一去不复还哎

Leave a Comment