Even steps
Inputs
n is a whole number from 0 to 40.
Your tasks
- Create an empty list
evens. - Use a loop to add every even number from 2 up to and including
ntoevens, in order. - Complete
evensUpToso it returnsevens. Return it, do not print it.
Example
With n = 9, evensUpTo returns [2, 4, 6, 8].
Rules
- Do not include 0.
- If
nis less than 2, return an empty list.
Test data
TEST DATA 1: n is 9
TEST DATA 2: n is 1
Practice focus
Loops that count, add up and multiply. Every algorithm starts here: a counter, a total and a stopping point.