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

  • by

Simple 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 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 start till the range in the list using for loop and check if num % 2 == 0. If the condition satisfies, 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 (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

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.