Python BasicsEasy

Fibonacci Series upto nth term

Detailed guide and Python implementation for the 'Fibonacci Series upto nth term' problem.

Problem Statement

Easy

Write a function fibonacci_series(n) that takes a non-negative integer n and returns a list containing the first n terms of the Fibonacci series. The Fibonacci series starts with 0 and 1, and each subsequent term is the sum of the two preceding terms. If n is 0, return an empty list.

Constraints
  • 0 <= n <= 50

Examples

Example 1
Input
n = 6
Output
[0, 1, 1, 2, 3, 5]
Explanation

The first 6 Fibonacci terms: 0, 1, 1 (0+1), 2 (1+1), 3 (1+2), 5 (2+3).

Example 2
Input
n = 1
Output
[0]
Explanation

The first 1 term of the Fibonacci series is just [0].

Example 3
Input
n = 0
Output
[]
Explanation

With n=0, there are no terms to return.

Need a Hint?
Consider using Basics-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor

Recommended Python Resources

Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.