Created
January 29, 2020 00:41
-
-
Save hazi98/6b11dd6edd72956f0a3b7a41ffe0b510 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 as ran | |
import math | |
# Variable de pi | |
pi = 0 | |
# Contador de dardos dentro del circulo | |
dardos_dentro = 0 | |
# Numero total de dardos a tirar | |
total = 10000 | |
for i in range(0, total): | |
# Generar coordenadas aleatorias x, y | |
x2 = ran.random()**2 | |
y2 = ran.random()**2 | |
# Preguntar si está dentro del circulo | |
if math.sqrt(x2 + y2) < 1: | |
dardos_dentro += 1 | |
# ( Ns / Nt ) * 4 | |
pi = (float(dardos_dentro) / total) * 4 | |
print("Valor aproximado de pi: ", pi) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment