Advertisement
dmemsm

Задача 7

Jan 12th, 2025
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.35 KB | None | 0 0
  1. # Воспользуемся методом Монте-Карло
  2.  
  3. import random
  4.  
  5. num_point_total = 10000000
  6. num_point_circle = 0
  7.  
  8. for i in range(num_point_total):
  9.     x = random.uniform(0, 1)
  10.     y = random.uniform(0, 1)
  11.     distance = x**2 + y**2
  12.  
  13.     if distance <= 1:
  14.         num_point_circle += 1
  15.  
  16. print(4 * num_point_circle/num_point_total)
  17.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement