Answered step by step
Verified Expert Solution
Question
1 Approved Answer
write this python program 5. Random walk. You may know that the streets and avenues of Manhattan form a grid. A random walk through the
write this python program
5. Random walk. You may know that the streets and avenues of Manhattan form a grid. A random walk through the grid (i.e., Manhattan) is a walk in which a random direction (N, E, S, or W) is chosen with equal probability at every intersection. For example, a random walk on a 5 11 grid starting at (5, 2) could visit grid points (6, 2), (7, 2), (8, 2), (9, 2), (10, 2), back to (9, 2) and then back to (10, 2) before leaving the grid. Write function manhattan ) that takes the number of rows and columns in the grid, simulates a random walk starting in the center of the grid, and computes the number of times each intersection has been visited by the random walk. Your function should print the table line by line once the random walk moves outside the grid. As an example, the call manhattan(5, 11) could produce the following output: Co, 0, o, o, 0, 0, 0, o, 0, 0, 0] [o, 0, 0, 0, 0, 0, 0, 0, o, 0, 0] to, 0, 0, 0, 0, 0, 0, 0, 0, o, 0] to, 0, 0, o, o, o, 0, 0, 0, 0, 0]Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started