Created
August 9, 2020 01:59
-
-
Save edwvilla/d6df1c28e593ffb7d492377d592dd8f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def estimate_pi(n): | |
num_point_circle = 0 | |
num_point_total = 0 | |
for _ in range(n): | |
x = random.uniform(0, 1) | |
y = random.uniform(0, 1) | |
distance = x**2 + y**2 | |
if distance <= 1: | |
num_point_circle += 1 | |
num_point_total += 1 | |
return 4 * num_point_circle/num_point_total | |
print(estimate_pi(10000)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment