Skip to content

Latest commit

 

History

History
45 lines (24 loc) · 1.2 KB

exercise_4.md

File metadata and controls

45 lines (24 loc) · 1.2 KB

Unit 5 Practice

Exercise 4 - Fibonacci / Tribonacci

The Fibonacci sequence is a series of numbers where each consecutive number is the sum of the previous two.

1.1

Write a loop that adds the first 10 values of the Fibonacci sequence to a list.

Display the list.

Hint: You can create your list using the first two numbers in the sequence [0,1]

Output

First ten Fibonacci numbers:
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]

1.2

Tri-bonacci! This is as it sounds. Create a new list of Tri-bonacci values where each consecutive number is the sum of the previous three numbers

Hint: You can create your list using the first three numbers in the sequence [0,1,1]

Output

First ten Tribonacci numbers:
[0, 1, 1, 2, 4, 7, 13, 24, 44, 81]

1.3

Write both the Fibonacci and Tribonacci sequence loops without providing the first two or three starting values.

1.4

Allow the user to enter the number of elements to calculate in both the Fibonacci and Tribonacci loops.

Exercise 4 solution