Software & Finance





Python - Sum of EVEN Numbers





 

I have given here python program to find the sum of EVEN numbers.

This code is tested with Python version 2.6

 

        print "Program to find the sum of Even numbers in the given range"
        
        beg = 0
        end = 0
        sum = 0
        n = 0
        
        print "Enter Starting Number:", 
        beg = input()
        print "Enter Ending Number:", 
        end = input()
        
        n = beg
        if ( (n  % 2) == 1):
           n += 1
        
        print "Adding Numbers : ", 
        while(n <= end):
           print n, 
           sum += n
           n += 2
        
        print "\nThe result is: ", sum
        
        
		#sample output
		#Program to find the sum of Even numbers in the given range
		#Enter Starting Number: 10
		#Enter Ending Number: 50
		#Adding Numbers :  10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50
		#The result is:  630