Discuss / Python / 利用list 计数

利用list 计数

Topic source

# -*- coding: utf-8 -*-

def move(n, a, b, c): 

    if n == 1:

        print(a, '-->', c)

        step.append(0)

    else:

        move(n-1,a,c,b)

        move(1,a,b,c)

        move(n-1,b,a,c)

n = int(input('amount of plates: '))

step = []

move(n, 'A', 'B', 'C')

print ('总共使用了 %d 步' % len(step))


  • 1

Reply