import random
def twoDRandomWalk(n = 100, printOn = False):
    location_x = 0
    location_y = 0
    length = 0
    step_x = 0
    step_y = 0

    while (abs(location_x)!= n and abs(location_y)!= n):
        step = random.randint(0, 3) # we have 4 directions, west, east, south, north
        if step == 0:               # 0 indicates west 
            step_x = -1             # hence x direction will be negative
        if step == 1:               # 1 indicates east
            step_x = 1              # hence x direction will be positive
        if step == 2:               # 2 indicates south
            step_y = -1             # hence y direction will be negative
        if step == 3:               # 3 indicates north
            step_y = 1              # hence y direction will be positive
        location_x = location_x + step_x    # update x location
        location_y = location_y + step_y    # update y location
        if printOn == True:                 # print location if printOn is true
            print location_x, location_y 
        step_x = 0                  # we should set the directions to zero, so that
        step_y = 0                  # direction from previous iteration is nor repeated
        length = length + 1         # update the length
    
    return length

#main program
print twoDRandomWalk()
