A robot moves in a plane starting from the origin point[0,0].. The robot can move toward UP, DOWN, LEFT, RIGHT. The trace of robot movements is as given following:

UP 5
DOWN 3
LEFT 3
RIGHT 2
The numbers after directions are steps. Write a program to compute the distance current position after sequence of movements.
Nov 13, 2020 in Python 3,391 views

Hello @

Try this code:

```import math

x, y = 0, 0

while True:
step = input("Type in UP/DOWN/LEFT/RIGHT #step number: ")

if step == "":
break

else:
step = step.split(" ")

if step[0] == "UP":
y = y + int(step[1])
elif step[0] == "DOWN":
y = y - int(step[1])
elif step[0] == "LEFT":
x = x - int(step[1])
elif step[0] == "RIGHT":
x = x + int(step[1])

c = math.sqrt(x**2 + y**2)

print("Distance:", c)```
• 82,880 points

+1 vote

Measuring the distance between pixels on OpenCv with Python

You can try this: Mat pts1(nPts, 1, CV_8UC2), ...READ MORE

Plot a k-distance graph in python

You probably want to use the matrix ...READ MORE

Measuring the distance between pixels on OpenCv with Python

Assuming input frames will have "close to ...READ MORE

Measuring the distance between pixels on OpenCv with Python

Assuming input frames will have "close to ...READ MORE