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).

25th Sep 2018, 5:23 PM
Nipun Jain
Nipun Jain - avatar
19 Respostas
+ 1
this is looking suspiciously like homework...
25th Sep 2018, 7:52 PM
LONGTIE👔
LONGTIE👔 - avatar
+ 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
25th Sep 2018, 10:30 PM
LONGTIE👔
LONGTIE👔 - avatar
+ 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
25th Sep 2018, 10:11 PM
Nipun Jain
Nipun Jain - avatar
+ 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
25th Sep 2018, 10:19 PM
LONGTIE👔
LONGTIE👔 - avatar
+ 2
show your attempt first, then we'll help you.
25th Sep 2018, 9:11 PM
LONGTIE👔
LONGTIE👔 - avatar
+ 2
Nipun Jain if the inputs are more than what?
25th Sep 2018, 10:24 PM
LONGTIE👔
LONGTIE👔 - avatar
+ 2
Good night Nipun Jain good luck with the code.
25th Sep 2018, 10:26 PM
LONGTIE👔
LONGTIE👔 - avatar
+ 2
25th Sep 2018, 10:27 PM
LONGTIE👔
LONGTIE👔 - avatar
+ 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
25th Sep 2018, 11:32 PM
dhm
+ 1
ok tnx bro....if inputs are more then can we use stop
25th Sep 2018, 10:23 PM
Nipun Jain
Nipun Jain - avatar
+ 1
LONGTIE👔 thanks for helping me
25th Sep 2018, 10:24 PM
Nipun Jain
Nipun Jain - avatar
+ 1
gud night LONGTIE👔
25th Sep 2018, 10:25 PM
Nipun Jain
Nipun Jain - avatar
+ 1
In everytime i will ask u problem
25th Sep 2018, 10:26 PM
Nipun Jain
Nipun Jain - avatar
0
yes,but i want how to code it
25th Sep 2018, 8:50 PM
Nipun Jain
Nipun Jain - avatar
0
tnx dude
25th Sep 2018, 10:27 PM
Nipun Jain
Nipun Jain - avatar
0
do u hv whatsapp number
25th Sep 2018, 10:27 PM
Nipun Jain
Nipun Jain - avatar
0
if yes then pls send it
25th Sep 2018, 10:28 PM
Nipun Jain
Nipun Jain - avatar
0
u are absoutely right dhm ....
26th Sep 2018, 5:46 AM
Nipun Jain
Nipun Jain - avatar
0
donner le code html ,css et js de ce probleme: Imagine you have a robot that needs to navigate through a maze to reach a target location starting from a given state. The robot can move in four directions (left, right, up, down) and has a map of the maze with walls, water, sand, grass, and empty spaces. The robot can use A* an AI-based algorithm to find the shortest path to reach the target location. The algorithm begins at the starting position and considers all possible moves (left, right, up, down) from the current position. The algorithm uses a heuristic function (For example the Manhattan distance formula) to estimate the cost of reaching the target location from each possible move and selects the move with the lowest estimated cost. The algorithm repeats this process until it reaches the target location or determines that it is not possible to reach the target. In this way, the AI algorithm helps the robot find the shortest path through the maze to reach the target location. The next steps can be followed in order to implement the program. 1. Create randomly a grid representing the map with differents type of cells (walls, water, empty spaces, etc.). 2. Implement a pathfinding algorithm A* to find the shortest path from point A (starting position) to point B (goal). 3. Allow the robot to follow the path and reach point B. We can consider some additional constraints : — The robot has a limited battery and can only move a certain number of steps before it needs to recharge. — The robot can only move on cells with a certain terrain type (e.g. water, sand, grass). — The robot has to avoid certain dangerous areas in the grid (for example successive water cells). — The robot’s movement is affected by the terrain type (e.g. moving on sand takes longer than moving on grass).
24th Feb 2024, 5:11 PM
Hadil asma Gouni
Hadil asma Gouni - avatar