Value of Pi
Theory
value of Pi is calculated using the Monte Carlo method - generate a large number of random points and see how many fall in the circle enclosed by the unit square.
# Program
from random import *
j=0
for i in range(10000000):
x=random()
y=random()
if (x**2+y**2)<=1:j+=1
print "Value of pi = ",4.0*j/i
value of Pi is calculated using the Monte Carlo method - generate a large number of random points and see how many fall in the circle enclosed by the unit square.
# Program
from random import *
j=0
for i in range(10000000):
x=random()
y=random()
if (x**2+y**2)<=1:j+=1
print "Value of pi = ",4.0*j/i
Comments
Post a Comment