#random_walk.py import random num_steps = int(input("Enter number of steps to make: ")) num_runs = int(input("Enter number of trials to make: ")) #prev_step = None distances = [] for run in range(num_runs): x = y = 0 #origin for i in range(num_steps): dir = random.randint(0,3) if dir == 0: y += 1 elif dir == 1: y -= 1 elif dir == 2: x += 1 else: x -= 1 distances.append(abs(x) + abs(y)) # print("manhattan distance from origin:",distances[run]) print(distances[run], end=" ") print() print("Min distance:",min(distances)) print("Max distance:",max(distances)) print("Avg distance:",sum(distances)/num_runs) #if even # steps, distance is even #if odd # steps, distance is odd #distro of distances is right skewed. #average is about sqrt of # steps, slightly higher