1 def fabm(n): 2 if n < 1: 3 print(‘输入不能小于1‘) 4 return -1 5 6 if n == 1 or n == 2: 7 return 1 8 else: 9 return fabm(n-1) + fabm(n-2) 10 11 result = fabm(19) 12 if result != -1: 13 print(‘结果是%d‘ % result)
时间: 2024-11-16 04:52:03
1 def fabm(n): 2 if n < 1: 3 print(‘输入不能小于1‘) 4 return -1 5 6 if n == 1 or n == 2: 7 return 1 8 else: 9 return fabm(n-1) + fabm(n-2) 10 11 result = fabm(19) 12 if result != -1: 13 print(‘结果是%d‘ % result)