Question: def find _ coordinates ( movements ) : x , y = 0 , 0 for move in movements: if move = = ' N

def find_coordinates(movements):
x, y =0,0
for move in movements:
if move =='N':
y +=1
elif move =='S':
y -=1
elif move =='E':
x +=1
elif move =='W':
x -=1
return (x, y)
# Test the function with the given examples
print(find_coordinates('NNE')) # Output: (1,2)
print(find_coordinates('NNEEENNW')) # Output: (2,4)
print(find_coordinates('WNENWNSNN')) # Output: (-1,4)
print(find_coordinates('EESSENNESE')) # Output: (5,-1)
print(find_coordinates('WEENEWE')) # Output: (2,1)
print(find_coordinates('NWEWWNSWW')) # Output: (-4,1)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!