count = 0
def hanoe(n, source, tmp, target):
global count
if n == 1:
count += 1
print('{:8d} :{}---->{}'.format(count, source, target))
else:
hanoe(n-1, source, target, tmp)
count += 1
print('{:8d} :{}---->{}'.format(count, source, target))
hanoe(n-1, tmp, source, target)
检验:hanoe(3,"A","B","C")
hanoe(3,'A','B','C')
1 :A---->C
2 :A---->B
3 :C---->B
4 :A---->C
5 :B---->A
6 :B---->C
7 :A---->C