In Pycharm I was trying out the monte carlo method to find distance from home

import random
def random_walk(n):
# Return coordinates after "n" block random walk

x = 0

y = 0

for i in range (n):
    step = random.choice(['N', 'S', 'E', 'W'])
    if step == 'N':
        y +=1
    elif step == 'S':
        y -=1
    elif step == 'E':
        x +=1
return(x, y)

for i in range (25):
    walk = random_walk(10)
    print(walk, "Distance From home = ",
          abs(walk[0]) + abs(walk[1]))

But, I'm getting this error

File "C:/Users///NewPhyton/", line 5 x = 0 ^ IndentationError: expected an indented block

Process finished with exit code 1

0 Answers 11

Not the answer you're looking for? Browse other questions tagged or ask your own question.