python求斐波那契数列示例分享

yipeiwu_com5年前Python基础

复制代码 代码如下:

def getFibonacci(num):
 res=[0,1]
 a=0
 b=1
 for x in range(0,num):
  if x==a+b:
   res.append(x)
   a,b=b,a+b
 return res

res=getFibonacci(1000)
print(res)

#递归
a=[0,1]
qian=0
def fibna(num,qian):
 print(num)
 he=num+qian
 if he<1000:
  a.append(he)
  qian=num
  fibna(he,qian)
fibna(1,0)
print(a)

相关文章

python读取word 中指定位置的表格及表格数据

python读取word 中指定位置的表格及表格数据

1.Word文档如下: 2.代码 # -*- coding: UTF-8 -*- from docx import Document def readSpecTable(filen...

Python 代码性能优化技巧分享

Python 代码性能优化技巧分享

如何进行 Python 性能优化,是本文探讨的主要问题。本文会涉及常见的代码优化方法,性能优化工具的使用以及如何诊断代码的性能瓶颈等内容,希望可以给 Python 开发人员一定的参考。...

Django应用程序入口WSGIHandler源码解析

前言 WSGI 有三个部分, 分别为服务器(server), 应用程序(application) 和中间件(middleware). 已经知道, 服务器方面会调用应用程序来处理请求, 在...

对python xlrd读取datetime类型数据的方法详解

使用xlrd读取出来的时间字段是类似41410.5083333的浮点数,在使用时需要转换成对应的datetime类型,下面代码是转换的方法: 首先需要引入xldate_as_tuple函...

python opencv3实现人脸识别(windows)

本文实例为大家分享了python人脸识别程序,大家可进行测试 #coding:utf-8 import cv2 import sys from PIL import Ima...