#_______________________________________________________________________
 
#4.py

 
#Let's estimate the value of pi using random numbers
 
#see http://www.coe.utah.edu/~hodgson/Monte_Carlo.html
 
# 1. Draw a circle of radius 1, centered at the origin
# 2. Focus only on first quadrant, draw a square of side 1 containing
#    part of circle in quadrant 1
# 3. Area of this part of circle is pi/4
# 4. Area of square is 1
 
# 5. q = Area of this part of circle / area of square = pi/4 
 
 
# 5. Throw darts (generate random points) at square
# 6. Estimate r = number of darts falling in circle part / total # of darts
# 7. Because r = pi/4, we get pi = 4*r

from random import * 

 
def throw_a_dart():
 
    xpt = random()      #x coordinate of dart
    ypt = random()      #y coordinate of dart
 
    if ((xpt**2 + ypt**2) <= 1):
        inside = 1
    else:
        inside = 0
 
    return(inside)   
 
 
def pi(N):
 
    in_count = 0   #number of darts falling inside circle part
 
    out_count = 0 #number of darts falling outside circle part
 
    for i in range(1,N+1,1,):
        
        s = throw_a_dart()
 
        if (s > 0):
            in_count = in_count + 1 
        else:
            out_count = out_count + 1

 
        total = in_count + out_count
 
        r = in_count/total
 
        pi_est = 4*r
 
    return(pi_est)
 

def main():
 
 
    N = eval(input("How many darts will you throw? "))
 
    est = pi(N)
 
    #Normally, we will not pass the same parameter "x" multiple
    #times, but since we are just focusing on how to print/draw
    #things in specific places in the graphics window, we will
    #overlook this bit of inefficiency
 
    #Our goal here was to give the function pi() places where
    #it needs to put labels and values in the graphics screen
 
    print(" Estimated value of pi: {0:0.3f}".format(est))
 
 
#______________________________________________________________________
main()
