The code box below defines a variable route as a list of directions to navigate a maze. Each instruction is one of the following four basic commands: higher. move one step in the positive y direction • lower: move one step in the negative y direction • left: move one step in the negative x direction right. move one step in the positive x direction ● ● Define a function step that takes two arguments, a location (as a tuple of x and y coordinates) and an instruction (higher, lower, left, right) as a string. Given the provided location, it should return the new location (as a tuple of xand y coordinates) when following the specified instruction. If the instruction is invalid, the old location should be returned. Use the function step to determine the final position when starting from the point (0, -4) and following all instructions in the list route. Assign this final position to the variable final_point.
The code box below defines a variable route as a list of directions to navigate a maze. Each instruction is one of the following four basic commands: higher. move one step in the positive y direction • lower: move one step in the negative y direction • left: move one step in the negative x direction right. move one step in the positive x direction ● ● Define a function step that takes two arguments, a location (as a tuple of x and y coordinates) and an instruction (higher, lower, left, right) as a string. Given the provided location, it should return the new location (as a tuple of xand y coordinates) when following the specified instruction. If the instruction is invalid, the old location should be returned. Use the function step to determine the final position when starting from the point (0, -4) and following all instructions in the list route. Assign this final position to the variable final_point.
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 27PE
Related questions
Question
100%
route = ['higher', 'higher', 'left', 'right', 'left', 'left', 'higher', 'left', 'right', 'left', 'right', 'left', 'left', 'lower', 'higher', 'lower', 'left', 'lower', 'right', 'higher', 'lower', 'left', 'left', 'lower', 'left', 'lower', 'right', 'right', 'higher', 'left', 'lower', 'lower', 'higher', 'lower', 'higher', 'lower', 'right', 'lower', 'right', 'left', 'higher', 'higher', 'right', 'right', 'right']
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 1 steps
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT