Question: Write a program in Python that reads in an initial position in a two-dimensional grid. The initial position consists of two integers separated by a
Write a program in Python that reads in an initial position in a two-dimensional grid. The initial position consists of two integers separated by a comma (i.e. an (x,y) coordinate). The program should also read in a movement string, consisting of the letters u,d,l,r,U,D,L,R. This sting specifies how we will move through the grid: u or U (Up): increase y by 1 d or D (Down): decrease y by 1 r or R (Right): increase x by 1 l or L (Left): decrease x by 1 The program should print out the initial position, read through the movement string and update the position of (x,y) and then print out the final coordinates, i.e. the (x,y) values after the movement is over. To get full marks, the program must be well written and include at least one good function. Examples: Initial position: 10,10 Movement: uUuRrRr Initial position: (10,10) Final position: (14,13) Initial position: 13,27 Movement: udlrUDRL Initial position: (13,27) Final position: (13,27) Initial position: 0,0 Movement: LLLD Initial position: (0,0) Final position: (-3,-1) Initial position: 23,32 Movement: UdUddUdrLLr Initial position: (23,32) Final position: (23,31) Initial position: 4,4 Movement: uUdrRl Initial position: (4,4) Final position: (5,5)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
