Created
August 31, 2013 05:32
-
-
Save Hydrotoast/6396391 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 prompt | |
import predicate | |
import random | |
DartThrown = prompt.for_int('Enter number of darts to throw', is_legal= predicate.is_positive) | |
count = 0 | |
for i in range(DartThrown): | |
#print('Dart Thrown') | |
x = random.uniform(-1, 1) | |
y = random.uniform(-1, 1) | |
#print(' x=', x,'/', 'y=', y) | |
if x**2+y**2 <= 1: | |
#print(' Inside Circle') | |
count += 1 | |
#print(' Inside Count', count) | |
#print(' Outside Circle') | |
#print(' Inside Count=', count) | |
pi_approximate = (count/DartThrown)*4 | |
print('pi is approximately =', pi_approximate) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment