Question:
Write a Python function called print_even_numbers()
that takes two integers, start
and end
, as input. The function should use a while loop to print all the even numbers between start
and end
(inclusive). If the provided start
is greater than the end
, the function should print "Invalid input: start should be less than or equal to end."
Example:
def print_even_numbers(start, end):
# Your code here
# Test cases
print_even_numbers(1, 10)
Expected Output:
2
4
6
8
10
print_even_numbers(7, 3)
Expected Output:
Invalid input: start should be less than or equal to end.
def printEvenNumber(start, end):
for i in range(start, end+1):
if i % 2 == 0:
print(i)
printEvenNumber(1, 10)