Display Even number up-to 20 by python by R4R Team

What is even number ?

Even nuumber are those number which on divide by 2 leaves a remainder of 0 like 0,2,4,6,.........

program to display even number upto 20 -

#first way
print("By for loop, even number upto 20")
for i in range(21):
if i%2==0:
print(i,end=" ")

#second way
print("nBy while loop,even number upto 20")
i=0
while(i<=20):
print(i,end=" ")
i=i+2


output -

By for loop, even number upto 20
0 2 4 6 8 10 12 14 16 18 20
By while loop,even number upto 20
0 2 4 6 8 10 12 14 16 18 20


In this program, in first part we use for loop in which we check every number that is even number or not but in second part we start with 0 value and increase the value by 2 and print upto 20.

Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!