Python - Print odd numbers
Python - Print odd numbers
CODE
def writeOddNumbers():
#Initialize the variable i to 1.
#This will be starting number that will be printed inside the loop.
i = 1
#The While loop prints the numbers from 1-9, 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
writeOddNumbers();
#OUTPUT
#1
#3
#5
#7
#9
Comments
Post a Comment