# Start writing code here...
x = 1+2; print(x)

from numpy import *
ntrials = 16000
nhits = 0
for iter in range(ntrials):
x,y = random.uniform(0,1), random.uniform(0,1)
if (x**2 + y**2) < 1 :
nhits+=1
area = 4*nhits/float(ntrials)
print("Pi is ", area)

from numpy import *
import numpy as np
import matplotlib.pyplot as plt
def findPiWithGraphics(N): #This is integration by darts method to find area of a quadrant of a unit circle within a unit square ... with the goal of finding pi
nhits = 0
xarray = np.array([]) #These will store points to plot
yarray = np.array([])
for iter in range(N):
x,y = random.uniform(0,1), random.uniform(0,1)
xarray = np.append(xarray,x)
yarray = np.append(yarray,y)
if (x**2 + y**2) < 1 :
nhits+=1
area = 4*nhits/float(N) #Multiply by 4 to get the area of the entire unit circle
areatuple = [area, xarray, yarray]
return(areatuple)
#First, calculate pi
N = 800 #This is the number of "trials" which is to say random points tossed onto a square
area=findPiWithGraphics(N)
print("Num trials is ", N, "and Pi is ", area[0])
# Now ready to plot the random points utilized in calculation
# make a circle with no fill, which is good for hi-lighting key results
circle2 = plt.Circle((0, 0), 1.0, color='b', fill=False)
ax = plt.gca()
ax.cla() # clear things for fresh plot
# change default range so that new circles will work
ax.set_xlim((-1, 1))
ax.set_ylim((-1, 1))
ax.set_aspect('equal')
# some data
#ax.plot(area[1],area[2]), 'o', color='black')
plt.scatter(area[1],area[2], color='grey')
ax.add_patch(circle2)
plt.savefig('testplot.png')