Find the slope of the given number | function to find slope of a number ; to store slope of the given number 'num ; loop from the 2 nd digit up to the 2 nd last digit of the given number 'num ; if the digit is a maxima ; if the digit is a minima ; required slope ; Driver Code
def slopeOfNum ( num , n ) : NEW_LINE ' NEW_LINE INDENT slope = 0 NEW_LINE DEDENT ' NEW_LINE INDENT for i in range ( 1 , n - 1 ) : NEW_LINE INDENT if ( num [ i ] > num [ i - 1 ] and num [ i ] > num [ i + 1 ] ) : NEW_LINE INDENT slope += 1 NEW_LINE DEDENT elif ( num [ i ] < num [ i - 1 ] and num [ i ] < num [ i + 1 ] ) : NEW_LINE INDENT slope += 1 NEW_LINE DEDENT DEDENT return slope NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT num = "1213321" NEW_LINE n = len ( num ) NEW_LINE print ( " Slope ▁ = " , slopeOfNum ( num , n ) ) NEW_LINE DEDENT