递归--汉诺塔

定义 

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)

调用

hanoi(5, "x", "y", "z")
发布了124 篇原创文章 · 获赞 21 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/tyustli/article/details/102680322