Sum of all even numbers in range L and R | Function to return the sum of all natural numbers ; Function to return sum of even numbers in range L and R ; Driver Code
def sumNatural ( n ) : NEW_LINE INDENT sum = ( n * ( n + 1 ) ) NEW_LINE return int ( sum ) NEW_LINE DEDENT def sumEven ( l , r ) : NEW_LINE INDENT return ( sumNatural ( int ( r / 2 ) ) - sumNatural ( int ( ( l - 1 ) / 2 ) ) ) NEW_LINE DEDENT l , r = 2 , 5 NEW_LINE print ( " Sum ▁ of ▁ Natural ▁ numbers " , " from ▁ L ▁ to ▁ R ▁ is " , sumEven ( l , r ) ) NEW_LINE