您的位置:首页 > 编程语言 > Python开发

python3实现简单汉诺塔

2018-03-19 09:00 190 查看
#!/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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: