Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

***python 3 1) A robot is put in a maze where it can only take a single step of length 1 at a time. The

***python 3

1) A robot is put in a maze where it can only take a single step of length 1 at a time. The step must be in one of the four following directions: up, down, left, or right. Based on the structure of the maze, a combination of steps in form of a string is provided to the robot so that it can find the right way to go through the maze. The string consists of a combination of directions of each step the robot has to take. That is:

A character u or U indicates taking a step up A character d or D indicates taking a step down A character l or L indicates taking a step to the left A character r or R indicates taking a step to the right

For example, an input string RuLUrd indicates that the robot must first take a step to the right, then a step up, then a step to the left, then a step up, then a step to the right and finally a step down in order to exit the maze.

1. Modify the function step_count() in file hw4.py so that this function takes the instruction string as input and returns the number of steps the robot has to take in order to go through the maze.

Example:

>>> step_count ( LRlURRDu )

8

2. Modify the function distance() in file hw4.py so that this function takes the instruction string as input and returns the distance (rounded to four decimal digits) between where the robot starts and the exit of the maze.

Example:

1>>> distance( LRlURRDu)

1.4142

3. You can assume that the inputs for both the function are always a string. However, if that input string consists of an invalid character, which is a character not in the set of {r,R,l,L,u,U, d, D}, both of the above functions must return -1

Example:

1 >>> step_count ( 7LRlURRDu )

-1

>>> distance(aLRlURRDu)

1

For distance calculation, we accept error within the range [-0.0001, +0.0001] so you dont have to worry about the error in rounding up or down

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Define Management by exception

Answered: 1 week ago

Question

Explain the importance of staffing in business organisations

Answered: 1 week ago

Question

What are the types of forms of communication ?

Answered: 1 week ago