Advertisement
Infiniti_Inter

ИМС_1

Apr 16th, 2022
771
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. from random import randint
  2.  
  3. def get_direction():
  4.     cur = randint(0, 3)
  5.     if (cur == 0):
  6.         return (0,1)
  7.     if (cur == 1):
  8.         return (1, 0)
  9.     if (cur == 2):
  10.         return (0, -1)
  11.     if (cur == 3):
  12.         return (-1, 0)
  13.  
  14. count_of_exp = int(1e4)
  15.  
  16.  
  17. fail = 0
  18. success = 0
  19.  
  20. for i in range(0, count_of_exp):
  21.     X, Y = (0, 0)
  22.     for j in range(0, 10):
  23.         x, y = get_direction()
  24.         X += x
  25.         Y += y
  26.     if (abs(X) + abs(Y) <= 2):
  27.         success += 1
  28.     else:
  29.         fail += 1
  30.  
  31. print(success/(success+fail))
  32.  
  33.    
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement