Use a while loop with if statement condition i % 2 == 0 then only print the first 10 even numbers in Python.
Example print first 10 even numbers using while loop 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 <= x: if i % 2 == 0: print(i, end=" ") i = i + 1
Without if statement
num = 2 while num <= 20: print(num) num = num + 2
Do comment if you have any doubts or suggestions on this Python even number topic.
Note: IDE: PyCharm 2021.3 (Community Edition)
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.