Created
October 19, 2015 14:46
-
-
Save Steffo99/649c854e899f5ce841c4 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 | |
import math | |
random.seed() | |
sqm = 0 | |
for prova in range(0, 5): | |
inside = 0 | |
for granello in range(0, 1000000): | |
x = random.random() | |
y = random.random() | |
if(x*x + y*y <= 1): | |
inside = inside + 1; | |
pi = inside / 1000000 * 4 | |
print(pi) | |
scarto = abs(3.1415926535 - pi) | |
sqm = sqm + scarto*scarto | |
print(sqm) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment