fibonacci()
Generate the first n Fibonacci numbers.
Usage
fibonacci(n)Computes the Fibonacci sequence starting from 0 and returns a list of the first n values.
Parameters
n: int-
The number of Fibonacci values to generate. Must be a positive integer.
Returns
list-
A list of the first
nFibonacci numbers.
Raises
ValueError-
If
nis less than 1.
Examples
>>> fibonacci(5)
[0, 1, 1, 2, 3]
>>> fibonacci(1)
[0]You can also use it with larger values:
>>> len(fibonacci(100))
100Edge case with exactly two values:
>>> fibonacci(2)
[0, 1]