Count Odd and Even numbers in a range from L to R | Return the number of odd numbers in the range [ L , R ] ; if either R or L is odd ; Driver code
def countOdd ( L , R ) : NEW_LINE INDENT N = ( R - L ) // 2 NEW_LINE if ( R % 2 != 0 or L % 2 != 0 ) : NEW_LINE INDENT N += 1 NEW_LINE DEDENT return N NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT L = 3 NEW_LINE R = 7 NEW_LINE odds = countOdd ( L , R ) NEW_LINE evens = ( R - L + 1 ) - odds NEW_LINE print ( " Count ▁ of ▁ odd ▁ numbers ▁ is " , odds ) NEW_LINE print ( " Count ▁ of ▁ even ▁ numbers ▁ is " , evens ) NEW_LINE DEDENT