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

Python 递归函数

2016-06-02 10:28 197 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/qq_27795381/article/details/51564425

汉诺塔移动


count = 1
2
3  def test(num, src, dst, rest):
4         global count
5
6         if num < 1:
7                 print False
8         elif num == 1:
9                 print "%d:\t%s -> %s" % (count, src, dst)
10                 count += 1
11         elif num > 1:
12                 test(num - 1, src, rest, dst)
13                 test(1, src, dst, rest)
14                 test(num - 1, rest, dst, src)
15
16
17 test(3, 'A', 'C', 'B')

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: