Loops and patterns · Python exercise
Print the first n terms of the Fibonacci sequence on one line.
Read a positive integer n and print the first n Fibonacci numbers separated by single spaces. The sequence starts 0, 1, 1, 2, 3, ...
Example 1
Input
7
Output
0 1 1 2 3 5 8
Example 2
Input
1
Output
0
How testing works
Your code runs once per test case with that case's standard input. Output is compared after normalising trailing spaces and blank lines at the end. Use input() without a prompt when the exercise expects clean output.
Loading editor…
Press Run tests to execute your code against every input case. Python runs in a Web Worker in your browser.