Python练习题11:汉诺塔实践

在这里插入图片描述

steps = 0
def hanoi(src,des,mid,n):
	global steps
	if n == 1:
		steps += 1
		print("[STEP{:>4}] {}->{}".format(steps,src,des))
	else:
		hanoi(src,mid,des,n-1)
		steps += 1
		hanoi(mid,des,src,n-1)
n = eval(input())
hanoi("A","C","B",n)		
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页