美文网首页
python 实现斐波那契数列

python 实现斐波那契数列

作者: 以我丶之姓 | 来源:发表于2019-04-18 17:42 被阅读0次
import sys
fib_list = []


def fib(max_num):
    a, b = 0, 1
    while b < max_num:
        fib_list.append(b)
        a, b = b, a+b
    print fib_list
    print "The Fibonacci sequence contained between 1 and %d has %d values !" % (max_num, len(fib_list))


if __name__ == "__main__":
    if len(sys.argv) != 2:
        print "please input argv"
    else:
        fib(int(sys.argv[1]))

相关文章

网友评论

      本文标题:python 实现斐波那契数列

      本文链接:https://www.haomeiwen.com/subject/ufntgqtx.html