Fibonacci Sequence
Fibonacci Sequence
Tags: Basics
Credit: CodingChallenge
Difficulty: Beginner
Type: Text
Category: Practice
Time Allowed: 5 s
Description:
Write a function that takes a positive integer N and returns a list containing the Fibonacci sequence up to N terms using a while loop. This problem is designed to help you practice using while loops and generating sequences
. The function should accept one parameter and return the Fibonacci sequence.
Constraints:
- The input will be a positive
integer
greater than zero. - The function should
return
alist
containing the Fibonacci sequence up to N terms.
Example:
- Input:
5
- Output:
[0, 1, 1, 2, 3]
Test Case | Input | Expected Output |
---|---|---|
1 | 1 | [0] |
2 | 2 | [0, 1] |
3 | 5 | [0, 1, 1, 2, 3] |
4 | 7 | [0, 1, 1, 2, 3, 5, 8] |
Leave a Comment
Please login to leave a comment.