我正在學習 itertools 并試圖測試在 python 中實現的 Binet 公式的準確性。使用 itertools 的原因是我假設這將需要大量迭代,并且只有在大量迭代后才會出現差異。from math import sqrtimport itertools#fibonacci function 2def fib1(): n = -1 while True: n += 1 yield int(((1+sqrt(5))**n-(1-sqrt(5))**n)/(2**n*sqrt(5)))#fibonacci function 1def fib2(): a,b = 0,1 while True: yield a a, b = b, a + br=itertools.dropwhile(lambda x: x[0]==x[1],itertools.zip_longest(fib1(),fib2()))for item in itertools.islice(r,0,1): print(item)輸出:(498454011879265, 498454011879264)在使用之前int()我使用round()過fib1(),結果是(308061521170130, 308061521170129)可以做些什么來提高我的比奈公式實現的準確性?
添加回答
舉報
0/150
提交
取消