Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #3.17
- import random
- from matplotlib import pyplot as plt
- import math
- a=[]
- #a[0]=x1
- #a[1]=y1
- #a[2]=x2
- #a[3]=y2
- x=[]
- y=[]
- n,N,M=0,10,0
- for _ in range (N):
- for i in range (4):
- a.append(random.uniform(-1, 1))
- if ((a[0])**2 + (a[1])**2)<= 1 and ((a[2])**2 + (a[3])**2) <= 1:
- M+=1
- if ((a[2] - a[0])**2 + (a[3] - a[1])**2)<1:
- n+=1
- #print(math.sqrt((a[2] - a[0])**2 + (a[3] - a[1])**2))
- a=[]
- print(n/M)
- '''
- plt.plot(x,y, linestyle="",marker="o")
- plt.title('PLOT')
- plt.show()
- '''
Advertisement
Add Comment
Please, Sign In to add comment