HomePython

Write a program to print first n even numbers in Python

Write a program to print first n even numbers in Python
Like Tweet Pin it Share Share Email

This program to print first n even numbers can be written in many ways, but as part of this article you will be introduced to a new concept in python, especially with a “for” loop. Value of variable increments or decrements automatically by step which can be given as part of the range function. You will also go through other ways of printing even numbers in this article.

Way 1 – Printing even numbers in Python using Step concept

In the above example, we have given n*2 as stop, the reason being, if you are to display n even numbers, in the range of 1 to n you will only have n/2 even numbers, and for printing n even numbers you need to double the range, which results in getting the desired number of even numbers i.e. n even numbers.

Way 2 – Printing even numbers in Python using simple for loop & if condition

Way 3 – Printing even numbers in Python using simple while loop

Like this there will be n number of solutions for the same problem, please feel free to share any of your queries in form of queries, we would be more than happy to respond to you.

Comments (0)

Leave a Reply

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