The Savings Jar Challenge

Working with ListsEasy+10 XP+10

The Savings Jar Challenge

Nadia is trying a savings challenge with a jar of coins. She picks how many coins go in during week 1 and week 2. From week 3 on, the rule never changes: each week's deposit is the two previous deposits added together.

Starting with 3 coins and then 4, the deposits go 3, 4, 7, 11, 18, and so on.

Task: write savings_plan(first, second, weeks) that returns a list of the deposits for the first weeks weeks, in order.

  • first and second are whole numbers, 0 or more.
  • weeks is a whole number, 0 or more. If it's 0, the plan is an empty list. If it's 1, the plan holds only the first week's deposit.

Start from 0 and 1 and you get one of the most famous number patterns in maths, the Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, …

Examples

first = 3
second = 4
weeks = 5
returns [3, 4, 7, 11, 18]
first = 0
second = 1
weeks = 8
returns [0, 1, 1, 2, 3, 5, 8, 13]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run