import random

# Programmer: Sriram Pemmaraju
# Date: Feb 10, 2012

# Version 2: moves the person at random, one step at a time, left or right,
# until the person reaches a barrier n or -n. Outputs the number of steps
# it took to reach the barrier

location = 0 # tracks the person's current location
n = 10 # value of the barrier
length = 0 # tracks the length of the random walk

# This moves the person until she reaches the barrier at n or -n
while abs(location) != n:    
    step = random.randint(0, 1) # returns 0 or 1, each with prob. 1/2

    # Adjusts the random number to be either -1 or +1
    if step == 0:
        step = -1    
    location = location + step # updates location
    length =  length + 1

print length
