求π的程序
import random
import math
paosha=1000000
yuan=0.0
for i in range(paosha+1):
a=random.random()
b=random.random()
c=math.sqrt(a2+b2)
if c<=1.0:
yuan=yuan+1
pi = 4*(yuan/paosha)
print(pi)
2023-11-24 21:17:52
import random
import math
paosha=1000000
yuan=0.0
for i in range(paosha+1):
a=random.random()
b=random.random()
c=math.sqrt(a2+b2)
if c<=1.0:
yuan=yuan+1
pi = 4*(yuan/paosha)
print(pi)