Need assist regarding my program

Here is my code. At present my program prints the coordinates now instead of printing coordinates I want it to print the direction like NESSWWEE. What should I do?

Hey @yashsharma4304 Do you want to print this? NESSWWEE

No, Suppose I give the Input as NNNSSEEWE so the output will be: x is 2, y is 1.
But instead of this output I want it gives me the output in terms of direction. Output I want : NEE (Displacement of the above path NNNSSEEWE).

Okay so you mean that you want a final output where it would be facing , right?

For this value of x & y output will be SE or ES

No, see let us take a short example to ask my doubt. A person walks 2 units north, 1 unit south, then 1 unit east i.e.(NNSE). So the final output that I want is the shortest path or the displacement of that person. So as we know the displacement would be 1 unit north 1 unit east i.e.(NE)

I don’t want to print the direction in which he is facing. I want to print that how much step he has to walk to reach through the shortest path in each direcion. NNEW means 2 units north, 1 unit east, 1 unit west.

That’s what I am saying bro, you want final answer in two characters, for that what you can do is judge value of x & y separately.
If x> 0 that means you will be at +x axis I.e., east
If x== 0 that means you will be at 0 coordinate
If x< 0 that means you will be at -x axis I.e., west

If Y>0 that means you will be at +y axis I.e., north
If Y==0 that means you will be at 0 coordinate
If Y< 0 that means you will be at -yaxis I.e., south

After judging your x and y value, print them

Ok ok now I understand. So now I need to put if else for these conditions and I will get my final output. Right?

Yes that’s how you will get your desired output :slight_smile:

1 Like

Ok thank u for your assist.