Skip to content

Instantly share code, notes, and snippets.

@ExReanimator
Created December 14, 2017 08:36
Show Gist options
  • Save ExReanimator/889eb3ab44fc6e93fb669b7fa16bdcb3 to your computer and use it in GitHub Desktop.
Save ExReanimator/889eb3ab44fc6e93fb669b7fa16bdcb3 to your computer and use it in GitHub Desktop.
import random
def inOut(x, y):
if x + y <= 1:
return True
else:
return False
def calc_pi(n):
return 4/n
for sample in [1000, 10000, 100000, 1000000]:
x = random.random()
y = random.random()
if inOut(x,y):
print("For a sample " + str(sample) + " and random point("+ str(x) + ", " + str(y) +") Pi is " + str(calc_pi(sample)))
else:
print("For a sample " + str(sample) + " and random point("+ str(x) + ", " + str(y) +") point is out of range")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment