当前位置: 移动技术网 > IT编程>脚本编程>Python > python3实现简单汉诺塔的代码教程

python3实现简单汉诺塔的代码教程

2018年03月21日  | 移动技术网IT编程  | 我要评论
python3实现简单汉诺塔的代码教程 #!/usr/bin/env python3 #_*_*_ coding: utf-8 _*_*_ #汉诺塔 # def

python3实现简单汉诺塔的代码教程

#!/usr/bin/env python3
#_*_*_ coding: utf-8 _*_*_

#汉诺塔

# def hannuota(n,N,M):
    # print("将第%d块从%s移动到第%s" %(n,N,M))
# def nuota(n,A,B,C):
    # if n==1:
        # hannuota(1,A,C)
    # else:
        # nuota(n-1,A,C,B)
        # hannuota(n-1,A,C)
        # nuota(n-1,B,A,C)    

    
def nuota(n,A,B,C):
    if n==1:
        # hannuota(1,A,C)
        print("将第%d块从%s移动到第%s" %(m,1,A,C))
        m = m+1
    else:
        nuota(n-1,A,C,B)
        # hannuota(n-1,A,C)
        print("将第%d块从%s移动到第%s" %((m+1),n,A,C))
        m = m+1
        nuota(n-1,B,A,C)

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网