Print Even Numbers in a Range

Easy ⏱ 8 min 79% acceptance ★★★★★ 4.5
Write a function evens_in_range(start, end) that returns a list of every even number from start to end inclusive, in ascending order, using a for loop.

Examples

Example 1
Input
evens_in_range(1, 10)
Output
[2, 4, 6, 8, 10]
Explanation

Even numbers between 1 and 10 inclusive.

Example 2
Input
evens_in_range(4, 4)
Output
[4]
Explanation

4 itself is even.

Constraints

  • start <= end, both integers.

Topics

Loopsrange()

Companies

TCSHCLTech

Hints

Hint 1

You can use `range(start, end + 1)` and filter with `% 2 == 0`, or step the range by 2 from the first even number.

Hint 2

Append qualifying numbers to a results list.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.