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

python_汉诺塔

2013-12-06 21:07 246 查看
save as hanoi.py,; then run:

#python hanoi.py 4

#!/bin/env python
import sys
import string

def hanoi(floor, towerA, towerB, towerC):
if (floor == 1):
print('get %s to %s'%(towerA,towerC))
else:
hanoi(floor - 1, towerA, towerC, towerB)
print('get %s to %s'%(towerA,towerC))
hanoi(floor - 1, towerB, towerA, towerC)

a=string.atoi(sys.argv[1])
hanoi(a, 'A', 'B', 'C')
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python string