在python中生成fibonacci数列的函数 def fibonacci(): list = [] while 1: if(len(list) < 2): list.append(1) else: list.append(list[-1]+list[-2]) yield list[-1] #1 # change this line so it yields its list instead of 1 our_generator = fibonacci() my_output = [] for…
# coding=gbk # 迭代法---1 def fibonacci (n): if n == 0 or n == 1: return n else : a = 0 b = 1 for i in range (n-1) : t = a a = b b = a + t return b number = eval (input ("请输入您要计算的斐波那契数列的项\n")) cc= fibonacci (number) print (cc) # 迭代法---2 def fibonac…