Robot problem | Sololearn: Learn to code for FREE!

0

Robot problem

A robot moves in a two-dimensional plane starting from the original position (0,0) by default. The program must confirm the same from the user. In case user wants to specify a different start point the program must update that. The robot can move toward UP, DOWN, LEFT and RIGHT. There are numbers after the direction, which are steps which the robot travels in that direction. The user gives information of the movement one by one in no specific order. In case the user gives a wrong input the program must prompt it to give the correct input. In case user inputs STOP, the program must then return initial, final coordinates of the robot and the distance from the traveled. A sample trace of robot movement is shown as the following: UP 5 DOWN 3 LEFT 3 RIGHT 2 UP 1 RIGHT 5 The output of this example will be 5 units with the initial position as (0,0) and final position (4,3).

9/25/2018 5:23:32 PM

Nipun Jain

18 Answers

New Answer

+1

this is looking suspiciously like homework...

+6

Nipun Jain no and sharing of whatsapp numbers is not allowed. put sololearn does have a discord server. plenty of people to help you on there. https://www.sololearn.com/discuss/689391/?ref=app

+4

this is my code import math #Init vars pos=[0,0] moves={"UP":[0,1], "DOWN":[0,-1], "LEFT":[-1,0], "RIGHT":[1,0]} #Set inputs """UP = int(input()) DOWN = int(input()) LEFT = int(input()) RIGHT = int(input())""" data = ["UP 5", "DOWN 3", "LEFT 2", "RIGHT 2"] #Move robot on valid moves for inp in data: parts=inp.split() mv=parts[0] val=parts[1] if mv in moves and val.isnumeric(): pos[0] = pos[0]+ moves[mv][0]*int(val) pos[1] = pos[1]+ moves[mv][1]*int(val) #get distance distance=math.sqrt(pos[0]**2 + pos[1]**2) print(distance, "from [0,0] to",pos) now pls tell me how to put data for any inputs

+3

I suggest removing the int from in front of the input, if I'm understanding your question right. https://code.sololearn.com/cTdHI0bSWQyE/?ref=app

+2

show your attempt first, then we'll help you.

+2

Nipun Jain if the inputs are more than what?

+2

Good night Nipun Jain good luck with the code.

+2

Nipun Jain ok.

+2

Based on your code and the post of longtie : your exercise specify that the user inputs the commands one by one (a command would be UP 4). If I were you, I would take the input once. Then depending on the input : -the user entered a wrong value, you ask him again -the user entered a correct value and you need to deal with it (read if it is up/down/left/right and the number) -the user entered STOP, so the program ends EDIT : in your exercise, the direction and the number of steps is separated by a whitespace. You might want to use the python split() method for strings. Check it

+1

ok tnx bro....if inputs are more then can we use stop

+1

LONGTIE👔 thanks for helping me

+1

gud night LONGTIE👔

+1

In everytime i will ask u problem

0

yes,but i want how to code it

0

tnx dude

0

do u hv whatsapp number

0

if yes then pls send it

0

u are absoutely right dhm ....