def move1(x1,x2):
print(x1,'-->',x2)
return
def hanoit(n,a,b,c):
if not isinstance(n,int):
raise TypeError(r'Bad Operand Type')
elif n<=0:
raise TypeError(r'"n" is not positive')
elif n==1:
move1(a,c)
else:
hanoit(n-1,a,c,b)
hanoit(n-1,b,a,c)
hanoit(3,'A','B','C')
Sign in to make a reply
遥云千鲤河
def move1(x1,x2):
print(x1,'-->',x2)
return
def hanoit(n,a,b,c):
if not isinstance(n,int):
raise TypeError(r'Bad Operand Type')
elif n<=0:
raise TypeError(r'"n" is not positive')
elif n==1:
move1(a,c)
else:
hanoit(n-1,a,c,b)
move1(a,c)
hanoit(n-1,b,a,c)
return
hanoit(3,'A','B','C')