Print Even Numbers in Range
Print all even numbers between 1 and a given upper limit.
BeginnerTopic: Loop Programs
Python Print Even Numbers in Range Program
This program helps you to learn the fundamental structure and syntax of Python programming.
# Program to print even numbers up to N
n = int(input("Enter upper limit: "))
for i in range(2, n + 1, 2):
print(i)Output
Enter upper limit: 10 2 4 6 8 10
Understanding Print Even Numbers in Range
We start from 2 and step by 2 using range(2, n + 1, 2) so every number printed is even.
Note: To write and run Python programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Python Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Python programs.