Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. import math
  2.  
  3. #Exo 2 page 63
  4. #Takes 3 numbers (nbqs= number of questions, nbp=total of possibilities per questions, nbpQ=parametre to win)
  5. class exo(object):
  6.  
  7. def __init__(self, nbqs, nbp, nbpQ):
  8. self.totalQuestions = nbqs #15
  9. self.ProbabilitySuccess = nbp #0.25
  10. self.parametreToWin=nbpQ #9
  11.  
  12. def calcul(self):
  13. pSucc = self.ProbabilitySuccess
  14. pLoss = 1- pSucc
  15. combinaisonFactor=(math.factorial(self.totalQuestions)/(math.factorial(self.parametreToWin)*(math.factorial(self.totalQuestions-self.parametreToWin))))
  16.  
  17. i = self.parametreToWin # C'est notre variable compteur que nous allons incrémenter dans la boucle
  18. total=0
  19. while i < self.totalQuestions: # Tant que i est strictement inférieure à 10
  20. total += combinaisonFactor*math.pow(pSucc, self.parametreToWin)*math.pow(pLoss, (self.totalQuestions-self.parametreToWin))
  21. i += 1 # On incrémente i de 1 à chaque tour de boucle
  22. return total
  23.  
  24. exo2=exo(15, 0.25, 9)
  25.  
  26. total=exo2.calcul()
  27.  
  28. print("La probabilite d'avoir réussi le cours sans réviser est de : " + str(total)+ " ou : " +str(round(total*100, 2))+"%")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement