递归递归
# 迭代方法def slowsnail(x):
am =
if x < 0:
print('输入错误!!!')
elif x == 1 or x == 2:
print('1')
elif x > 2:
for i in range(0, x - 2):
b = am + am
am.append(b)
print(am)
return am
number = int(input('输入一个整数:'))
a = slowsnail(number)
print(a)
# 递归
def funcation(x):
if x < 0:
print('输入错误!!!')
elif x == 1 or x == 2:
return 1
elif x > 2:
return funcation(x - 1) + funcation(x - 2)
number = int(input('输入一个整数:'))
a = funcation(number)
print(a)
页:
[1]