Skip to content

Write a program to display even numbers between 10 and 20 in Python

  • by

Using the range() function you can Write a program to display even numbers between 10 and 20 in Python. You need to define start, stop, and step parameters.

range(start, stop, step) 

Example display even numbers between 10 and 20 in Python

Simple example code using step set to 2 because the start value is an even number.

for i in range(10, 20, 2):
    print(i)

Output:

Write a program to display even numbers between 10 and 20 in Python

Another way

Iterate from the start till the range in the list using the for loop and check if num % 2 == 0. If the condition is satisfied, then only print the number.

start, end = 10, 20

for num in range(start, end + 1):

    # checking condition
    if num % 2 == 0:
        print(num, end=" ")

Output: 10 12 14 16 18 20

Do comment if you have any doubts or suggestions on this Python number topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading