Advertisement
Guest User

Task #2

a guest
Mar 26th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.81 KB | None | 0 0
  1. import pandas as pd
  2. from math import factorial
  3. BlackT = 35
  4. OrangeT = 5
  5. BlueT = 2
  6. RedT = 8
  7. Total = BlackT + OrangeT + BlueT + RedT
  8. #Inputs of A
  9. N = Total
  10. K = BlackT
  11. n = 25
  12. k = 20
  13. HypergeometricD = ((factorial(K)/(factorial(k)*factorial(K-k)))*(factorial(N-K)/(factorial(n-k)*factorial(N-K-(n-k)))))/(factorial(N)/(factorial(n)*factorial(N-n)))
  14. Combinations = factorial(N)/(factorial(n)*factorial(N-n))
  15. Black = 10
  16. Orange = 0
  17. Blue = 0
  18. Red = 0
  19. i = 0
  20. df = pd.DataFrame(columns=['Black','Orange','Blue','Red','ProbabilityV', 'Variants'])
  21. while Black <= 25:
  22.     Orange = 0
  23.     while Orange <= OrangeT:
  24.         Blue = 0
  25.         while Blue <= BlueT:
  26.             Red = 0
  27.             while Red <= RedT:
  28.                 if Black+Orange+Blue+Red == 25:
  29.                     BlackC = factorial(BlackT)/(factorial(Black)*factorial(BlackT-Black))
  30.                     OrangeC = factorial(OrangeT)/(factorial(Orange)*factorial(OrangeT-Orange))
  31.                     BlueC = factorial(BlueT)/(factorial(Blue)*factorial(BlueT-Blue))
  32.                     RedC = factorial(RedT)/(factorial(Red)*factorial(RedT-Red))
  33.                    
  34.                     Variants = BlackC*OrangeC*BlueC*RedC
  35.                    
  36.                     ProbabilityV = Variants/Combinations
  37.                    
  38.                     df.loc[i] = [Black, Orange, Blue, Red, ProbabilityV, Variants]
  39.                     i += 1
  40.                 Red += 1
  41.             Blue += 1
  42.         Orange += 1
  43.     Black += 1
  44. ProbabilityT = 0
  45. CheckT = 0
  46. VariantsT = 0
  47.  
  48. for index, row in df.iterrows():
  49.     ProbabilityT += row["ProbabilityV"] * row["ProbabilityV"]
  50.     CheckT += row["ProbabilityV"]
  51.     VariantsT += row["Variants"]
  52. print("Probability of A case =", "{:10.12f}".format(HypergeometricD))
  53. print("Probability of B case =", "{:10.12f}".format(ProbabilityT))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement