不知道错哪了
def move(n, a, b, c):
def fact(n):
t1=='a-->b'
t2=='b-->c'
t3=='a-->c'
if n==1:
print t1
elif n>1:
print t1
print (n-1)*t2
print (n-1)*t3
move(4, 'A', 'B', 'C')
def move(n, a, b, c):
def fact(n):
t1=='a-->b'
t2=='b-->c'
t3=='a-->c'
if n==1:
print t1
elif n>1:
print t1
print (n-1)*t2
print (n-1)*t3
move(4, 'A', 'B', 'C')
2020-01-09
您理解错啦,a,b,c是形参,不是实参,我参考了知乎上的一位答主对于汉诺塔递归的解释https://www.zhihu.com/question/24385418
附上我的代码,供您参考
def move(n, a, b, c):
if n <= 0 :
return "the number must larger than zero !"
elif n == 1 :
print a, '-->', c
return
else :
move(n-1, a, c, b)
print a, '-->', c
move(n-1, b, a, c)
move(4, 'A', 'B', 'C')
举报