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
Chapter7: User-defined Simple Data Types, Namespaces, And The String Type
Section: Chapter Questions
Problem 7PE
icon
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']

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.
Transcribed Image Text: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.
Expert Solution
steps

Step by step

Solved in 1 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr