Discuss / Python / 打卡Day4

打卡Day4

Topic source

VH立华

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

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

    if n == 1:

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

    else:

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

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

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

hanoi(3, 'A', 'B', 'C')

From:百度百科


  • 1

Reply