# L-15.5 MCS 260 Mon 21 July 2014 : estimpi.py

"""
Recall the Monte Carlo method to estimate Pi.
"""

from math import pi
from random import uniform as u

print 'approximating pi = %.14f' % pi
(COUNT, TOTAL) = (0, 0)
NRAW = raw_input('give number of samples : ')
N = int(NRAW)
for i in range(0, N):
    TOTAL += 1
    (X, Y) = (u(0, 1), u(0, 1))
    if X**2 + Y**2 <= 1:
        COUNT += 1
APPROX = (4.0*COUNT)/TOTAL
print '#samples : %d, estimate : %.14f' % (TOTAL, APPROX)
