Tuesday 6 November 2012

Sum and Number of Even's in 1 to 50 using If and For Loop?


sum=0
counter=0
for i in range(0,50):
    if i%2==0:
        sum=sum+i
        counter=counter+1
print 'Number Of Even is =',counter
print 'Sum is =',sum

No comments:

Post a Comment