Created
July 15, 2018 12:25
-
-
Save solen003/09be3f02b72032c166a41070b44f6318 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def random_walk2(n): | |
"""n number of blocks to walk""" | |
x, y = 0, 0 | |
for i in range(1, n): | |
(dx, dy) = random.choice([(0, 1), (0, -1), (-1, 0), (1, 0)]) | |
x = x + dx | |
y = y + dy | |
return(x, y) | |
for i in range(1, 26): | |
location = random_walk2(10) | |
print(i, location, "Distance from home: ", abs(location[0]) + abs(location[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment