python递归算法举例

#递归算法举例
# #数制转换
def foo(num,base):
  	if num >= base:
            foo(num // base, base)
            print(num % base, end = '')

numA = int(input("a"))
numB = int(input("b"))
foo(numA, numB)
#你可试试base=2

#汉诺塔
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)  
        # 将n-1个盘子从a移动到b上,再将b上的n-1个盘子移动到c上  即a->b->c                       
hanoi(3, 'A', 'B', 'C')