tu as bien compris.
du moment où l'incrémentation de k se fait après le calcul de p=p(X<=k),
pour récupérer la valeur de k qui correspond à p, il faut afficher k-1.
bonne année babahand !
juste pour le fun, le même programme, mais avec des fonctions.
from math import factorial as fact
def binomial(a, b):
return fact(a)/(fact(b) * fact(a - b))
def calcul_proba(n,k,p):
return binomial(n,k)*p**k *(1-p)**(n-k)
def seuil(n, p, maxi) :
p_cumul = k = 0
while p_cumul < maxi :
p_cumul += calcul_proba(n,k,p)
print("p( X<=", k, ") =", p_cumul)
k=k+1
return k-1
print("k = ", seuil(80, 0.02192, 0.9))
p( X<= 0 ) = 0.1698049223979682
p( X<= 1 ) = 0.47424823165393604
p( X<= 2 ) = 0.7437550152362475
p( X<= 3 ) = 0.9007946296841771
k = 3
Vous devez être membre accéder à ce service...
Pas encore inscrit ?
1 compte par personne, multi-compte interdit !
Ou identifiez-vous :