Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 编写斐波那契函数_Python - Fatal编程技术网

Python 编写斐波那契函数

Python 编写斐波那契函数,python,Python,编写一个函数fibonnaci(),该函数接受: 作为输入的绑定 并返回其最大Fibonaci数小于界限的Fibonaci序列 菲邦纳奇(12) 1,1,2,3,5,8, 给你 def fib(maximum): if maximum<2: return [] current=[1,1] while True: candidate=sum(current[-2:]) if candidate>=maximum:

编写一个函数fibonnaci(),该函数接受: 作为输入的绑定 并返回其最大Fibonaci数小于界限的Fibonaci序列

菲邦纳奇(12)

1,1,2,3,5,8,

给你

def fib(maximum):
    if maximum<2:
        return []
    current=[1,1]
    while True:
        candidate=sum(current[-2:])
        if candidate>=maximum:
            break
        current.append(candidate)
    return current
def fib(最大值):
如果最大值=最大值:
打破
当前.附加(候选)
回流
def fibonize(绑定):
温度=0
lst=[1]
尽管如此:
如果lst[len(lst)-1]<绑定:
一级附加(一级[长(一级)-1]+温度)
温度=lst[透镜(lst)-2]
其他:
lst.pop()
打破
返回lst

您能否展示您尝试过的内容以及遇到的困难。
def fibonize(bound):
   temp = 0
   lst = [1]
   while True:
     if lst[len(lst) - 1] < bound:
        lst.append(lst[len(lst) - 1] + temp)
        temp = lst[len(lst) - 2]
     else:
        lst.pop()
        break
return lst