218,178 views
31 votes
31 votes
Python:

A two dimensional random walk simulates the behavior of a particle moving in agrid of points. At each step, the random walker moves north, south, east, or westwith probability14, independent of previous moves. Compose a program thattakes a command-line argumentnand estimates how long it will take a randomwalker to hit the boundary of a 2n-by-2nsquare centered at the starting point.

How do I solve this?

So far i have the following:

import sys
import stdio
import random

# the size of the box, which should be 4
n = int(sys.argv[1])

# should be the amount of steps taken to reach the boundary/ end of the box.
c = int(sys.argv[2])

def random_walk_2D (n):
x, y = 0, 0
i = 4
North = 1; South = 2; West = 3; East = 4

for i in range(n):

people = random.randint(1,4)

while I < c:
stdio.write()

if people == 1:
y = y + 1
elif people == 2:
y = y - 1
elif people == 3:
x = x + 1
else :
x = x - 1
return (x, y)

User Sagunms
by
3.2k points

1 Answer

18 votes
18 votes
Bghnnngz hg figuring
User Antoine
by
3.2k points