# Créé par nyckie, le 05/05/2019 en Python 3.4

from math import*
from random import*
def echvar(V,P,n,N):
    A=paramvar(V,P)
    mu=A[0]; sigma=A[2]
    c=0
    for k in range(N):
        m=moysimvar(V,P,n)
        if abs(m-mu)<=2*sigma/sqrt(n):
            c=c+1
    return(c/N)


from math import*
def paramvar(V,P):
    mu=0;Var=0
    for i in range(len(V)):
         mu=mu+V[i]*P[i]
    for i in range(len(V)):
        Var=Var+(V[i]-mu)**2*P[i]
    sigma=sqrt(Var)
    return [mu,Var,sigma]

def simvar(V,P,n):
    N=[0,0,0,0]
    y=P[0]
    z=y+P[1]
    t=z+P[2]
    for i in range(n):
        a=random()
        if 0<a<y:
            N[0]=N[0]+1
        if y<a<z:
            N[1]=N[1]+1
        if z<a<t:
            N[2]=N[2]+1
        if a>t:
            N[3]=N[3]+1
    F=[N[0]/n,N[1]/n,N[2]/n,N[3]/n]
    return(F)


def moysimvar(V,P,n):
    E=0
    F=simvar(V,P,n)
    for i in range(4):
        E=E+V[i]*F[i]
    return E
