Print even numbers

Created by Julien Palard

Write a function printing every even numbers in the given range, one number per line.

Your function have to be named print_even_numbers and accept two parameters named start and stop.

Like Python's range, you'll have to start searching for even numbers by including start but excluding stop, remember:

for i in range(0, 10):
    print(i)

gives:

0
1
2
3
4
5
6
7
8
9

so what I want print_even_numbers(0, 10) to give:

0
2
4
6
8

Hints

You can use the remainder of a value divided 2 to tell if it's odd or even. And in Python to get this remainder use the % operator, see:

>>> 2 % 2
0
>>> 3 % 2
1
>>> 4 % 2
0
>>> 5 % 2
1
>>> 6 % 2
0

The remainder is 1 if the value is odd and 0 if the value is even.

You'll have to use an if statement and a print.

There's no corrections yet, hit the `Submit` button to send your code to the correction bot.

Keyboard shortcuts:

  • Ctrl-Enter: Send your code to the correction bot.
  • Escape: Get back to the instructions tab.

See solutions