Discuss / Python / 加个显示步骤数目的小功能

加个显示步骤数目的小功能

Topic source

学生Summer

#1 Created at ... [Delete] [Delete and Lock User]
#递归
i = 1
def move(n, a, b, c):
    global i
    if n == 1:
        print('Step:', i, a, '-->', c)
        return
    move(n-1, a, c, b)
    i = i + 1
    print('Step:', i, a, '-->', c)
    i = i + 1
    move(n-1, b, a, c)
move(3,'A','B','C')

  • 1

Reply