Fibonacci numbers
Read n and print the first n numbers of the Fibonacci sequence on one line, separated by spaces.
The sequence starts 0 1, and every number after that is the sum of the two before it: 0 1 1 2 3 5 8 ...
Input
5
Expected output
0 1 1 2 3
Input
1
Expected output
0
Show a hint
Keep two variables for the last two numbers and update them together: a, b = b, a + b.
Show a solution
Loading the editor…
Run the tests to check your solution.