Comment on fait ?
Genre créer le vecteur je trouve ça difficile
Ca me perturbe que on crée le vecteur avant d'initialiser i je sais pas si l'algorithme est correct
J'ai essayé ça mais ça marche pas
def simul_loi_var_discr(x, p): F[i] = sum(p[0:i]) i = 0 choix = rand() while choix > F[i]: i += 1 return x[i]
def simul_loi_var_discr(x, p): i = 0 F=[] F.append(sum(p[0:i+1])) choix = rand() while choix > F[i]: i += 1 del F[:] return x[i]
Celle là me met list index out of range
def simul_loi_var_discr(x, p): i = 0 F=[] F.append(sum(p[0:i+1])) choix = rand() while choix > F[i]: i += 1 return x[i]
Je comprends pas pour ça marche pas
def simul_loi_var_discr(x, p): F = [] for i in range(len(p)): F.append(sum(p[0:i+1])) choix = rand() while choix > F[i]: i += 1 return x[i]
Je craque
Ah yep ça a l'air de marcher !
Merci