Print even numbers
Created on Dec. 9, 2016 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:
1 2 | |
gives:
1 2 3 4 5 6 7 8 9 10 | |
so what I want print_even_numbers(0, 10) to give:
1 2 3 4 5 | |
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:
1 2 3 4 5 6 7 8 9 10 | |
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.