+2 votes
in Programming Languages by (74.2k points)
Can I get a python code for the first N numbers of the Fibonacci series?

1 Answer

+1 vote
by (349k points)
selected by
 
Best answer

Here is the python code for the first N numbers of the Fibonacci series.

# first n Fibonacci numbers
def fibonacciNumbers(n):
    nums = []
    a, b = 0, 1
    for i in range(n):
        nums.append(a)
        a, b = b, a + b
    return nums

if __name__ == "__main__":
    print(fibonacciNumbers(10))

The above code will output the following numbers:

[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]


...