Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # Gabriel Antonio Videtta (2021)
- import random
- def estimate_pi(runs=1_000_000):
- total = 0
- circle_points = 0
- for _ in range(runs):
- if random.random() ** 2 + random.random() ** 2 <= 1:
- circle_points += 1
- total += 1
- return 4 * circle_points / total
- print(estimate_pi())
Add Comment
Please, Sign In to add comment