hearot

Untitled

Mar 12th, 2021 (edited)
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.36 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. # Gabriel Antonio Videtta (2021)
  4.  
  5. import random
  6.  
  7.  
  8. def estimate_pi(runs=1_000_000):
  9.     total = 0
  10.     circle_points = 0
  11.  
  12.     for _ in range(runs):
  13.         if random.random() ** 2 + random.random() ** 2 <= 1:
  14.             circle_points += 1
  15.  
  16.         total += 1
  17.  
  18.     return 4 * circle_points / total
  19.  
  20.  
  21. print(estimate_pi())
  22.  
Add Comment
Please, Sign In to add comment