Find the direction from given string | Function to find the final direction ; if count is positive that implies resultant is clockwise direction ; if count is negative that implies resultant is anti - clockwise direction ; Driver code
def findDirection ( s ) : NEW_LINE INDENT count = 0 NEW_LINE d = " " NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT if ( s [ i ] == ' L ' ) : NEW_LINE INDENT count -= 1 NEW_LINE DEDENT else : NEW_LINE INDENT if ( s [ i ] == ' R ' ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT DEDENT if ( count > 0 ) : NEW_LINE INDENT if ( count % 4 == 0 ) : NEW_LINE INDENT d = " N " NEW_LINE DEDENT elif ( count % 4 == 10 ) : NEW_LINE INDENT d = " E " NEW_LINE DEDENT elif ( count % 4 == 2 ) : NEW_LINE INDENT d = " S " NEW_LINE DEDENT elif ( count % 4 == 3 ) : NEW_LINE INDENT d = " W " NEW_LINE DEDENT DEDENT if ( count < 0 ) : NEW_LINE INDENT count *= - 1 NEW_LINE if ( count % 4 == 0 ) : NEW_LINE INDENT d = " N " NEW_LINE DEDENT elif ( count % 4 == 1 ) : NEW_LINE INDENT d = " W " NEW_LINE DEDENT elif ( count % 4 == 2 ) : NEW_LINE INDENT d = " S " NEW_LINE DEDENT elif ( count % 4 == 3 ) : NEW_LINE INDENT d = " E " NEW_LINE DEDENT DEDENT return d NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT s = " LLRLRRL " NEW_LINE print ( findDirection ( s ) ) NEW_LINE s = " LL " NEW_LINE print ( findDirection ( s ) ) NEW_LINE DEDENT