Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- def get_direction():
- cur = randint(0, 3)
- if (cur == 0):
- return (0,1)
- if (cur == 1):
- return (1, 0)
- if (cur == 2):
- return (0, -1)
- if (cur == 3):
- return (-1, 0)
- count_of_exp = int(1e4)
- fail = 0
- success = 0
- for i in range(0, count_of_exp):
- X, Y = (0, 0)
- for j in range(0, 10):
- x, y = get_direction()
- X += x
- Y += y
- if (abs(X) + abs(Y) <= 2):
- success += 1
- else:
- fail += 1
- print(success/(success+fail))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement