我正在尝试在 Python 3.3.2 中编写一个简短的函数。这是我的模块:
from math import sqrt
phi = (1 + sqrt(5))/2
phinverse = (1-sqrt(5))/2
def fib(n): # Write Fibonacci numbers up to n using the generating function
list = []
for i in range(0,n):
list = list.append(int(round((phi**i - phinverse**i)/sqrt(5), 0)))
return(list)
def flib(n): # Gives only the nth Fibonacci number
return(int(round((phi**n - phinverse**n)/sqrt(5), 0)))
if __name__ == "__main__":
import sys
fib(int(sys.argv[1]))
当我运行 fibo.fib(6) 时,我收到以下错误:
list = list.append(int(round((phi**i - phinverse**i)/sqrt(5), 0)))
AttributeError: 'NoneType' object has no attribute 'append'
我该如何纠正这个错误?