Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #3.17
- import random
- from matplotlib import pyplot as plt
- a=[]
- #a[0]=x1
- #a[1]=y1
- #a[2]=x2
- #a[3]=y2
- n,N=0,1000000
- for _ in range (N):
- for i in range (4):
- a.append(random.uniform(-1, 1))
- if (a[0])**2 + (a[1])**2 <= 1:
- if (a[2])**2 + (a[3])**2 <= 1:
- if (((a[2] - a[0])**2 + (a[3] - a[1])**2)**(1/2))<1:
- n+=1
- a=[]
- print(n/N)
Advertisement
Add Comment
Please, Sign In to add comment