|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
# 迭代方法
def slowsnail(x):
am = [1, 1]
if x < 0:
print('输入错误!!!')
elif x == 1 or x == 2:
print('1')
elif x > 2:
for i in range(0, x - 2):
b = am[i] + am[i + 1]
am.append(b)
print(am)
return am[x - 1]
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) |
|