from random import random
List = [0,0]
for i in range(0,1000000):
x = random()
y = random()
if pow(x,2)+pow(y,2)<=1:
List[0] += 1
else:
List[1] += 1
print 4*float(List[0])/(i + 1)
#================另一种实现方式===============
from random import random
n = 1000000
print sum(1 if random()**2 + random()**2 <= 1 else 0 for i in range(n))*4.0/n