---
title: "Fibonacci sequence up to N terms"  
description: "Fibonacci sequence up to N terms"  
author: "ICSM Computer"  
published: 2025-09-08  
updated: 2025-09-08  
canonical: https://www.mindstick.com/interview/34368/fibonacci-sequence-up-to-n-terms  
category: "python"  
tags: ["python-3.4", "Python 3"]  
reading_time: 2 minutes  

---

# Fibonacci sequence up to N terms

## Fibonacci Sequence

The Fibonacci sequence is a series of numbers where:

```plaintext
F(0) = 0
F(1) = 1
F(n) = F(n-1) + F(n-2)   (for n ≥ 2)
```

So the sequence looks like:\
`0, 1, 1, 2, 3, 5, 8, 13, ...`

## Python Program (up to N terms)

```python
def fibonacci(n):
    sequence = []
    a, b = 0, 1   # first two numbers

    for i in range(n):
        sequence.append(a)  # store current number
        a, b = b, a + b     # move to next two numbers

    return sequence

# Example
terms = 10
print(f"Fibonacci sequence up to {terms} terms:")
print(fibonacci(terms))
```

### Output for `terms = 10`

```plaintext
Fibonacci sequence up to 10 terms:
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
```

## Explanation

- Start with `a = 0`, `b = 1`.
- Loop runs `n` times.
- On each iteration:

   - Append `a` to the sequence.
   - Update `a, b` → shift forward (`a` becomes `b`, `b` becomes `a+b`).

- Continue until we generate `n` terms.

## Answers

### Answer by ICSM Computer

## Fibonacci Sequence

The Fibonacci sequence is a series of numbers where:

```plaintext
F(0) = 0
F(1) = 1
F(n) = F(n-1) + F(n-2)   (for n ≥ 2)
```

So the sequence looks like:\
`0, 1, 1, 2, 3, 5, 8, 13, ...`

## Python Program (up to N terms)

```python
def fibonacci(n):
    sequence = []
    a, b = 0, 1   # first two numbers

    for i in range(n):
        sequence.append(a)  # store current number
        a, b = b, a + b     # move to next two numbers

    return sequence

# Example
terms = 10
print(f"Fibonacci sequence up to {terms} terms:")
print(fibonacci(terms))
```

### Output for `terms = 10`

```plaintext
Fibonacci sequence up to 10 terms:
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
```

## Explanation

- Start with `a = 0`, `b = 1`.
- Loop runs `n` times.
- On each iteration:

   - Append `a` to the sequence.
   - Update `a, b` → shift forward (`a` becomes `b`, `b` becomes `a+b`).

- Continue until we generate `n` terms.


---

Original Source: https://www.mindstick.com/interview/34368/fibonacci-sequence-up-to-n-terms

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
