Problem Description A two-dimensional random walk simulates the behavior of a particle moving in a grid of points. At each step, the random walker moves north, south, east, or west with an equal probability of 1/4, regardless of previous moves. Using the turtle module write a program that visualizes the steps of a random walker in a 400 x 400 square starting from the origin (i.e., position 0, 0). Use a step of size, n = 20 (i.e. 10 successive steps in one direction from the origin will get to a boundary). Your program shall define the following functions: • draw_bounds (size, center=(0,0)): This function shall draw a square with the given dimension (i.e. size parameter) around a given starting point (i.e. center parameter). NOTE: The turtle must return to the starting point/center position and its initial orientation after drawing the square • step(step_size=20): This function shall implement a single step in the random walk. The turtle moves by the given step_size in a randomly chosen direction i.e. North, South, East or West • walk (limits=(-200, 200)): This function shall iteratively invoke the previously defined step function to implement the random walk until the turtle reaches a boundary (i.e. defined by the given limits). Additionally, this function must return the number of steps taken. Apply the defined functions in your program to implement 1 trial of the random walk. Display the number of steps taken on the screen once the walk is complete.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

please write in python languag and by end include the output to make sure it works.

 

thanks

Template:

# imports


def draw_bounds(size, center=(0, 0)):
    """This function shall draw a square with the given dimension (i.e. size parameter)
     around a given starting point (i.e. center parameter).
     NOTE: The turtle must return to the starting point/center position
     and its initial orientation after drawing the square"""


def step(step_size=20):
    """This function shall implement a single step in the random walk.
    The turtle moves by the given step_size in a randomly chosen
    direction i.e. North, South, East or West"""


def walk(limits=(-200, 200)):
    """This function shall iteratively invoke the step function to implement
    the random walk until the turtle reaches a boundary (i.e. defined by the given limits).
    Additionally, this function must return the number of steps taken."""


if __name__ == '__main__':
    ...
2-D Random Walk
Steps taken= 142,
T
0
X
Transcribed Image Text:2-D Random Walk Steps taken= 142, T 0 X
Problem Description
A two-dimensional random walk simulates the behavior of a particle moving in a grid of points.
At each step, the random walker moves north, south, east, or west with an equal probability of
1/4, regardless of previous moves.
Using the turtle module write a program that visualizes the steps of a random walker in a
400 x 400 square starting from the origin (i.e., position 0, 0). Use a step of size, n = 20 (i.e. 10
successive steps in one direction from the origin will get to a boundary).
Your program shall define the following functions:
•
draw_bounds (size, center= (0,0)): This function shall draw a square with the
given dimension (i.e. size parameter) around a given starting point (i.e. center
parameter). NOTE: The turtle must return to the starting point/center position and its
initial orientation after drawing the square
step(step_size=20): This function shall implement a single step in the random walk.
The turtle moves by the given step_size in a randomly chosen direction i.e. North,
South, East or West
• walk (limits=(-200, 200)): This function shall iteratively invoke the previously
defined step function to implement the random walk until the turtle reaches a boundary
(i.e. defined by the given limits). Additionally, this function must return the number of
steps taken.
Apply the defined functions in your program to implement 1 trial of the random walk. Display
the number of steps taken on the screen once the walk is complete.
Transcribed Image Text:Problem Description A two-dimensional random walk simulates the behavior of a particle moving in a grid of points. At each step, the random walker moves north, south, east, or west with an equal probability of 1/4, regardless of previous moves. Using the turtle module write a program that visualizes the steps of a random walker in a 400 x 400 square starting from the origin (i.e., position 0, 0). Use a step of size, n = 20 (i.e. 10 successive steps in one direction from the origin will get to a boundary). Your program shall define the following functions: • draw_bounds (size, center= (0,0)): This function shall draw a square with the given dimension (i.e. size parameter) around a given starting point (i.e. center parameter). NOTE: The turtle must return to the starting point/center position and its initial orientation after drawing the square step(step_size=20): This function shall implement a single step in the random walk. The turtle moves by the given step_size in a randomly chosen direction i.e. North, South, East or West • walk (limits=(-200, 200)): This function shall iteratively invoke the previously defined step function to implement the random walk until the turtle reaches a boundary (i.e. defined by the given limits). Additionally, this function must return the number of steps taken. Apply the defined functions in your program to implement 1 trial of the random walk. Display the number of steps taken on the screen once the walk is complete.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Mathematical functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education