Exercise: Loops
Take on this exercise to practice your skills of loops.
Exercise 1: Even sequence generator
Problem statement
Your task is to complete the EvenNumbers
function by adding a loop that will collect the first n
even numbers into a list. The sequence of even numbers starts from 0
and increases by 2
each time, for example, 0, 2, 4, 6, up to a maximum of 18.
You are provided with a function that already has a list declared for you. Your job is to fill this list with the correct even numbers until you have n
numbers in the list. Remember, you do not need to create the function and only need to add the loop that will generate the even numbers.
Sample input
The number n
is int
.
Expected output
If n = 2
, the output is expected to be [0,2]
. Similarly, if n = 10
, the output is expected to be [0,2,4,6,8,10,12,14,16,18]
.
Get hands-on with 1400+ tech skills courses.