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

1 Answer

0 votes
by (22.3k points)

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]

...