Find the final co | Function to print the final position of the point after traversing through the given directions ; Traversing through the given directions ; If its north or south the point will move left or right ; If its west or east the point will move upwards or downwards ; Returning the final position ; Driver Code
def finalCoordinates ( SX , SY , D ) : NEW_LINE INDENT for i in range ( len ( D ) ) : NEW_LINE INDENT if ( D [ i ] == ' N ' ) : NEW_LINE INDENT SY += 1 NEW_LINE DEDENT elif ( D [ i ] == ' S ' ) : NEW_LINE INDENT SY -= 1 NEW_LINE DEDENT elif ( D [ i ] == ' E ' ) : NEW_LINE INDENT SX += 1 NEW_LINE DEDENT else : NEW_LINE INDENT SX -= 1 NEW_LINE DEDENT DEDENT ans = ' ( ' + str ( SX ) + ' , ' + str ( SY ) + ' ) ' NEW_LINE print ( ans ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT SX , SY = 2 , 2 NEW_LINE D = " NSSE " NEW_LINE finalCoordinates ( SX , SY , D ) NEW_LINE DEDENT