To write a program to print the first 10 even numbers in Python, you have a set range of for loop. In this example, you have to use max loop 10. Then if the current number % 2 == 0 matches the condition in the
if statement then prints it. Simple example code. Output:maximum = 10
for number in range[1, maximum + 1]:
if number % 2 == 0:
print[number]
Python Program to Print Even Numbers from 1 to N
Print the even number from 1 to the user’s given number.
maximum = int[input["Enter the Maximum Value : "]]
for number in range[1, maximum + 1]:
if number % 2 == 0:
print["{0}".format[number]]
Output:
Enter the Maximum Value: 5
2
4
Do comment if you have any doubts or suggestions on this Python print number code.
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.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.
Use a while loop with if statement condition i % 2 == 0 then only print the first 10 even numbers in Python. Simple example code print even numbers of user input value using a while loop in Python. You can use list objects to store value, here we are printing the value using the end keyword.x = int[input["Enter a number: "]]
i = 1
while i