斐波那契数列python实现
斐波,那契,数列,python,实现
2025-04-07 09:01:29 时间
大家好,又见面了,我是你们的朋友全栈君。
方法一
def fbnc(n):
if not isinstance(n,int):
raise ValueError('n must be int')
if n == 1:
return [1]
elif n == 2:
return [1,1]
elif n > 2:
l = [1,1]
for i in range(n-2):
l.append(l[-1] + l[-2])
return l
方法二
def fbnc2(n):
a,b = 1,1
for i in range(n-2):
a,b = b,a+b
return b
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/156132.html原文链接:https://javaforall.cn
相关文章
- 自动编码器重建图像及Python实现
- 用Python教训盗号骗子
- python浮雕图片_python图片处理PIL
- Python实现商场管理系统
- Python-drf前戏38.2-前端Vue02
- python lasso回归分析_解析python实现Lasso回归「建议收藏」
- 使用python根据关键词批量获取Nature文章信息
- Python 第三方模块 科学计算 SciPy模块1 简介,常数,IO「建议收藏」
- 造数据神器Faker,一个有趣又实用的Python第三方库
- Python自动化办公小程序:实现报表自动化和自动发送到目的邮箱
- Python 一网打尽<排序算法>之堆排序算法中的树
- Python 树表查找_千树万树梨花开,忽如一夜春风来(二叉排序树、平衡二叉树)
- python基础知识
- python anaconda jupyter_anaconda和pip
- Python一键生成国庆渐变头像
- Python 敏感词过滤的实现「建议收藏」
- Python中的语法糖甜不甜?
- Python实现物流管理系统
- python dtype o_python – 什么是dtype(’O’)? – 堆栈内存溢出「建议收藏」
- [33]python Web 框架:Tornado