# Les intervalles de fluctuation¶

## Les paramètres¶

In [1]:
import math
p=0.7
n=100


## En seconde¶

In [2]:
k=1/math.sqrt(n)

a=p-k
b=p+k

print(f"I=[{a:.8f} ; {b:.8f}]")

I=[0.60000000 ; 0.80000000]


## En terminale¶

In [3]:
k=1.96*math.sqrt(p*(1-p))/math.sqrt(n)

a=p-k
b=p+k

print(f"I=[{a:.8f} ; {b:.8f}]")

I=[0.61018152 ; 0.78981848]


## En Première¶

In [4]:
#------------------------------------------------------
def fact(n) :
"Calcule factoriel n."
if (n==0) :
return 1
else :
p=1
for k in range(1,n+1):
p=p*k
return p

#------------------------------------------------------
def combin (n,k):
"Calcule  k parmi n."
p=1
for i in range(n-k+1,n+1) :
p=p*i
return p//fact(k)

def binomial(n,p,k):
"Calcule p(x=k)"
return math.exp(math.log(combin(n,k))+k*math.log(p)+(n-k)*math.log(1-p))

cumul=0
d=dict() # dictionaire des (k,p(x=k))
for k in range(n+1):
cumul+=binomial(n,p,k)
d[k]=cumul

for (c,v) in d.items() : # recherche de a
if v>0.025 :
a=c
break

for (c,v) in d.items() : # recherche de b
if v>0.975 :
b=c
break

print(f"I=[{a/n:.8f} ; {b/n:.8f}]")

I=[0.61000000 ; 0.79000000]

In [16]:
d_bas=dict((c,v) for (c,v) in d.items() if a-10<c<a+10)
for (c,v) in d_bas.items():
print(f"{c:4d} | {v:.6f}")
if (c==a-1):
print("------------------ 0,025")

  52 | 0.000117
53 | 0.000256
54 | 0.000537
55 | 0.001086
56 | 0.002115
57 | 0.003968
58 | 0.007174
59 | 0.012498
60 | 0.020989
------------------ 0,025
61 | 0.033979
62 | 0.053046
63 | 0.079880
64 | 0.116079
65 | 0.162858
66 | 0.220742
67 | 0.289281
68 | 0.366892
69 | 0.450876
70 | 0.537660

In [14]:
d_haut=dict((c,v) for (c,v) in d.items() if b-10<c<b+10)
for (c,v) in d_haut.items():
print(f"{c:4d} | {v:.6f}")
if (c==b-1):
print("------------------ 0,975")

  70 | 0.537660
71 | 0.623222
72 | 0.703634
73 | 0.775601
74 | 0.836870
75 | 0.886430
76 | 0.924469
77 | 0.952134
78 | 0.971169
------------------ 0,975
79 | 0.983537
80 | 0.991113
81 | 0.995477
82 | 0.997837
83 | 0.999031
84 | 0.999595
85 | 0.999843
86 | 0.999943
87 | 0.999981
88 | 0.999994

In [ ]: