TheAceHome

Untitled

Oct 14th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. #3.17
  2. import random
  3. from matplotlib import pyplot as plt
  4. a=[]
  5. #a[0]=x1
  6. #a[1]=y1
  7. #a[2]=x2
  8. #a[3]=y2
  9. n,N=0,1000000
  10. for _ in range (N):
  11. for i in range (4):
  12. a.append(random.uniform(-1, 1))
  13. if (a[0])**2 + (a[1])**2 <= 1:
  14. if (a[2])**2 + (a[3])**2 <= 1:
  15. if (((a[2] - a[0])**2 + (a[3] - a[1])**2)**(1/2))<1:
  16. n+=1
  17.  
  18. a=[]
  19.  
  20. print(n/N)
Advertisement
Add Comment
Please, Sign In to add comment