Discuss / Python / 交作业

交作业

Topic source

loveprruy

#1 Created at ... [Delete] [Delete and Lock User]
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
def move(n,a,b,c,num=[1]):
    if n==1:
       print(num[0],':',a,'->',c)
    else:
        move(n-1,a,c,b)
        num[0]=num[0]+1
        move(1,a,b,c)
        num[0]=num[0]+1
        move(n-1,b,a,c)   
move(3,'a','b','c')

  • 1

Reply