Advertisement
OreganoHauch

Probability for drawing beans out of a pot_Test #1

Mar 30th, 2020
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import math
  2.  
  3. # big beans
  4. B = 100
  5.  
  6. # small beans
  7. b = 100
  8.  
  9. # beans on plate ( p = numB + numb )
  10. p = 10
  11.  
  12. # EXAMPLE: probability for p = 10 big beans
  13. probability_10bigbeans = 1
  14. for i in range(p):
  15. probability_10bigbeans *= (B-i)/(B+b-i)
  16. print(probability_10bigbeans)
  17.  
  18. # probability for (numB, numb) distribution:
  19. def distribution_probability(numB, numb):
  20. probability_numB_numb = math.factorial(numB+numb)/(math.factorial(numb+1)*math.factorial(numB))
  21. for i in range(numB):
  22. probability_numB_numb *= (B-i)/(B+b-i)
  23. for i in range(numb):
  24. probability_numB_numb *= (b-i)/(B+b-numB-i)
  25. return(probability_numB_numb)
  26.  
  27. print(distribution_probability(0,10))
  28.  
  29. def expectation_value(p):
  30. expected_i_B = 0
  31. expected_i_b = 0
  32. for i_B in range(p):
  33. for i_b in range(p):
  34. expected_i_B += distribution_probability(i_B, i_b)*i_B
  35. expected_i_b += distribution_probability(i_B, i_b)*i_b
  36. print("The expectation value for", str(p), "beans on the plate", "(out of", str(B), "big beans and", str(b), "small beans in the pot) is:\n\n", str(expected_i_B), "big beans,\n", "and", str(expected_i_b), "small beans.")
  37.  
  38. expectation_value(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement