# 666 253骰子 经常无数次得到的概率是一样的验证
# sinx cosx 在0~360的 定积分
import random
import math
def fun():
a = random.randint(1, 6)
b = random.randint(1, 6)
c = random.randint(1, 6)
if a == 6 and b == 6 and c == 6:
return 1
if a == 2 and b == 5 and c == 3:
return 2
n = 200000 # 越大越显示
a666 = 0
a253 = 0
for i in range(1, n):
if fun() == 1:
a666 += 1
if fun() == 2:
a253 += 1
print(a666 / n)
print(a253 / n)
s = 0
PI = 3.1415926
def integration(f, endPos, startPos):
totalArea = 0
n1 = 1000000
width = (endPos - startPos) / n1
for ii in range(1, n1+1):
x = startPos + width * ii
area = f(x) * width
totalArea = totalArea + area
totalArea = ('%.19f' % totalArea)
return totalArea
print(integration(math.sin, 2 * 3.1415926, 0))
print(integration(math.cos, 2 * 3.1415926, 0))