Python 编写斐波那契函数
编写一个函数fibonnaci(),该函数接受: 作为输入的绑定 并返回其最大Fibonaci数小于界限的Fibonaci序列 菲邦纳奇(12) 1,1,2,3,5,8, 给你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:
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