TheAceHome

Untitled

Oct 14th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #3.17
  2. import random
  3. from matplotlib import pyplot as plt
  4. import math
  5. a=[]
  6. #a[0]=x1
  7. #a[1]=y1
  8. #a[2]=x2
  9. #a[3]=y2
  10. x=[]
  11. y=[]
  12. n,N,M=0,10,0
  13. for _ in range (N):
  14. for i in range (4):
  15. a.append(random.uniform(-1, 1))
  16. if ((a[0])**2 + (a[1])**2)<= 1 and ((a[2])**2 + (a[3])**2) <= 1:
  17. M+=1
  18. if ((a[2] - a[0])**2 + (a[3] - a[1])**2)<1:
  19. n+=1
  20. #print(math.sqrt((a[2] - a[0])**2 + (a[3] - a[1])**2))
  21. a=[]
  22.  
  23. print(n/M)
  24. '''
  25. plt.plot(x,y, linestyle="",marker="o")
  26. plt.title('PLOT')
  27. plt.show()
  28. '''
Advertisement
Add Comment
Please, Sign In to add comment