Discuss / Python / 有个想法

有个想法

Topic source

要在每一步前显示这是第几次移动(序号)的话该怎么写呢...

苏生不语_

#2 Created at ... [Delete] [Delete and Lock User]

# -- coding: utf-8 -- #定义一个全局变量步数 step=1;

def move(n, a, b, c): #使用全局变量step global step if n == 1: print(step,':',a, '-->', c) step=step+1 else: move(n-1,a,c,b) print(step,':',a, '-->', c) step=step+1 move(n-1,b,a,c) move(3, 'A', 'B', 'C')


  • 1

Reply