2013-02-25 51 views
0

我已经写了一些代码来输出Fibonacci序列两个第八项:我该如何解决我的错误? (输出“无”)

def fibonacci(): 
    a=1 
    b=1 
    print (a) 
    print (b) 
    for i in range(0,8): 
     current= a+b 
     print (current) 
     a=b 
     b=current 

它的工作原理,但我的输出对最终字没有,为什么我收到此错误?

1 
1 
2 
3 
5 
8 
13 
21 
34 
55 
None 

我使它输出1,1所以我的序列不会在2

+0

你打电话像'print(fibonacci())''也许? – 2013-02-25 18:36:21

+2

删除函数签名中的'8',它没有做任何事情。 – 2013-02-25 18:36:58

+0

8使我的序列输出8个数字 – 2013-02-25 18:39:38

回答

4

开始我怀疑你调用这样的功能:

print(fibonacci(8)) 

如果你是,删除print()

fibonacci(8)