ulvis.paste.net

Paste Search Dynamic
Recent pastes
Relative probability
  1. import random
  2. def probability_even(a):
  3.     cards = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
  4.             14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
  5.              29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,42,
  6.              43, 44, 45, 46, 47, 48, 49, 50, 51, 52]
  7.  
  8.     success = 0
  9.     failures = 0
  10.     x=[]
  11.     y=[]
  12.     z=[]
  13.  
  14.     for i in range(1, a +1):
  15.         z.append(i)
  16.         card = random.choice(cards)
  17.         if card == 2:
  18.             x.append(card)
  19.             success = success + 1
  20.             relative_probability = round(success/ i, 6)
  21.             print('Relative probability:' + str(relative_probability))
  22.             print('\nCummulative Probability: ' + str(success/a))
  23.  
  24.         else:
  25.             y.append(card)
  26.             faiures = failures + 1
  27.  
  28.  
  29.     print('\nSuccesses: '+ str(success) + '\n' + '\nSuccesses cards:')
  30.     print(x)
  31.     print('\nFailure cards:')
  32.     print(y)
  33.  
  34. probability_even(100)
  35. probability_even(100)
Parsed in 0.015 seconds