Python - Print even numbers
Python - Print even numbers
CODE
def writeEvenNumbers():
#Initialize the variable i to 2.
#This will be starting number that will be printed inside the loop.
i = 2
#The While loop prints the numbers from 2-10, in increments of 2.
#The condition i <= 10 takes care of exiting from the while loop.
while(i <= 10):
print(i)
#The variable i is incremented by 2 below.
#This will take care of printing the next number when the loop is executed next.
i = i + 2
writeEvenNumbers();
#OUTPUT
#2
#4
#6
#8
#10
Comments
Post a Comment