Challenge
PastOne concept, three rungs. Reaching rung 1 is the goal, so climb as far as you can.
Multiples And Leftovers
loops + remainders
Count the threes
Write a function called count_threes
A number is a multiple of 3 if dividing it by 3 leaves no remainder. Return how many numbers in the list are multiples of 3. Zero counts as a multiple of 3.
Examples
| Input | Output |
|---|---|
| [1, 2, 3, 4, 5, 6] | 2 |
| [] | 0 |
| [3] | 1 |
| [0] | 1 |
There are extra hidden tests, so make it work in general, not just for these.
Add up the multiples
Write a function called sum_multiples
Now you choose the number to check. Add up every number in the list that is a multiple of n and return the total. n is always 1 or more, and an empty list gives 0.
Examples
| Input | Output |
|---|---|
| [1, 2, 3, 4, 5, 6], 3 | 9 |
| [], 5 | 0 |
| [10], 5 | 10 |
| [1, 2], 5 | 0 |
There are extra hidden tests, so make it work in general, not just for these.
Multiples in a range
Write a function called multiples_between
This time there is no list to start with — you build one. Return a list of every multiple of n from start up to end, including both ends. If start is bigger than end, return an empty list.
Examples
| Input | Output |
|---|---|
| 1, 10, 3 | [3, 6, 9] |
| 5, 5, 5 | [5] |
| 10, 1, 2 | [] |
| 1, 6, 1 | [1, 2, 3, 4, 5, 6] |
There are extra hidden tests, so make it work in general, not just for these.
Finish Rung 1 and today counts. Rungs 2 and 3 are there if you want to push further.