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 523 views

## 1 answer to this question.

+1 vote

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 == "UP":
y = y + int(step)
elif step == "DOWN":
y = y - int(step)
elif step == "LEFT":
x = x - int(step)
elif step == "RIGHT":
x = x + int(step)

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

print("Distance:", c)``` answered Nov 13, 2020 by
• 82,780 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