python 递归-汉诺塔
Posted vvrr
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 递归-汉诺塔相关的知识,希望对你有一定的参考价值。
# 汉诺塔 a = "A" b = "B" c = "C" def hano(a, b, c, n): if n == 1: print(" --> ".format(a, c)) if n == 2: print(" --> ".format(a, c)) print(" --> ".format(a, b)) print(" --> ".format(b, c)) return None hano(a, b, c, n - 1) print(" --> ".format(a, c)) hano(b, a, c, n - 1) hano(a, b, c, 5)
A --> C A --> B B --> C A --> C B --> C B --> A A --> C A --> C B --> C B --> A A --> C B --> C A --> C A --> B B --> C A --> C B --> C B --> A A --> C B --> C A --> C A --> B B --> C B --> C A --> C A --> B B --> C A --> C B --> C B --> A A --> C
以上是关于python 递归-汉诺塔的主要内容,如果未能解决你的问题,请参考以下文章