How to write the Fibonacci Sequence?

前端 未结 30 2382
醉酒成梦
醉酒成梦 2020-11-22 00:32

I had originally coded the program wrongly. Instead of returning the Fibonacci numbers between a range (ie. startNumber 1, endNumber 20 should = only those numbers between 1

30条回答
  •  别那么骄傲
    2020-11-22 01:15

    It can be done by the following way.

    n = 0
    
    numbers = [0]
    
    for i in range(0,11):
        print n,
        numbers.append(n)
        prev = numbers[-2]
        if n == 0:
            n = 1
        else:
            n = n + prev
    

提交回复
热议问题