#Program to determine the pi value by Monte carlo method:
from math import*
import random as rn
nt=input("Enter the total no. darts:")
nt=int(nt)
ns=0.0
for i in range (nt):
x=rn.random()
y=rn.random()
x1=-1+2*x
y1=-1+2*y
if sqrt(x1**2+y1**2)<=1:
ns=ns+1
A=4*ns/nt
print("The value of pi is:",A)
from math import*
import random as rn
nt=input("Enter the total no. darts:")
nt=int(nt)
ns=0.0
for i in range (nt):
x=rn.random()
y=rn.random()
x1=-1+2*x
y1=-1+2*y
if sqrt(x1**2+y1**2)<=1:
ns=ns+1
A=4*ns/nt
print("The value of pi is:",A)
Comments
Post a Comment