Question: basic libraries only Write a python function walk(n) that that takes a positive integer and generates instructions for a random walk n yards away from
basic libraries only
Write a python function walk(n) that that takes a positive integer and generates instructions for a random walk n yards away from the starting position. The valid motion directions are North, South, East, and West. The user walks 1 yards in a randomly drawn direction. At the end of each 10-yard walk, a random direction is selected again, and the process continues. Return the number of draws it took to get to n yards away from the starting point and terminate the program. The following shows how the function would behave.
Hint: You can define variables to keep the East-West and North-South distance from the starting position (similar to X and Y direction) with East and North denoted by positive values. Also, the distance on an XY plane from the origin is given by the square root of x coordinate^2 +y coordinate^2.
>>> walk()
426
>>> walk()
78
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
