Discuss / Python / zuoye

zuoye

Topic source

Sense菜

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

def move(n, a, b, c):
if n==1: print(a,"-->",c); else: move(n-1,a,c,b); move(1,a,b,c); move(n-1,b,a,c);

墨111帅哥

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

while 1: x = 0 def hanio(n,a,b,c): if n == 1: move(a,c) else: hanio(n-1,a,c,b) move(a,c) hanio(n-1,b,a,c) def move(a,c): global x x = x + 1 print("%s-->%s " % (a,c),end = ' ') if x%5 == 0: print("\n") t = int(input()) if t==0: break hanio(t,'a','b','c') print("\n")


  • 1

Reply