1 #recursion.py:打印斐波那契数列 2 def fact(n): 3 if n==1 or n==2: 4 return 1 5 else: 6 return fact(n-1)+fact(n-2) 7 while 1==1: 8 test=eval(input("请输入数字:")) 9 for i in range(1,test+1): 10 print("第{}次打印:".format(i),fact(i))
1 #recursion.py:打印斐波那契数列 2 def fact(n): 3 if n==1 or n==2: 4 return 1 5 else: 6 return fact(n-1)+fact(n-2) 7 while 1==1: 8 test=eval(input("请输入数字:")) 9 for i in range(1,test+1): 10 print("第{}次打印:".format(i),fact(i))