There is a robot which wants to go the charging point to charge itself.
The robot moves in a 2-D plane from the original point (0,0). The robot can move toward UP, DOWN, LEFT and RIGHT with given steps.
The trace of robot movement is shown as the following:
UP 5
DOWN 3
LEFT 3
RIGHT 2
Then, the output of the program should be:
2
The numbers after the direction are steps.
Write a program to compute the distance between the current position after a sequence of movement and original point. If the distance is a float, then just print the nearest integer (use round() function for that and then convert it into an integer).
Answers
Answer:
no I didn't know that
Explanation:
Gu family Book of Mormon tabernacle choir and orchestra and choir and orchestra and choir and orchestra and choir and orchestra and choir and orchestra and choir and orchestra and choir and orchestra and Chorus line High Court Pani Da rang me the opportunityad the the of download free music downloads and orchestra and chorus concert poster flyer for our next meeting will take care love to see if I can get a chance to look at the moment I would like me to
Answer:
import math
position = [0,0]
moves = []
s = int(input())
for i in range(s):
moves=list(input().split())
direction = moves[0].upper()
steps = int(moves[1])
if direction=="UP":
position[0] += steps
elif direction=="DOWN":
position[0] -= steps
elif direction=="LEFT":
position[1] -= steps
elif direction=="RIGHT":
position[1] += steps
else:
pass
print(round(math.sqrt(position[0]**2+position[1]**2)))
Explanation:
You can use this way to get distance between starting and ending point.
Hope it helps.