helvette

Untitled

Oct 24th, 2021
827
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # you have 3 different boxes: first have 2 white balls, second have black and white, and the third have 2 black balls. this program will tell you the chance of taking the 2 balls of same color from a random box.
  2. import random
  3. counter1 = 0
  4. box1 = ['white', 'white']
  5. box2 = ['black', 'white']
  6. box3 = ['black', 'black']
  7. i = 0
  8. print('please input the number of runs')
  9. a = int(input())
  10. while i < a:
  11.     box = random.randint(0, 2)
  12.     if box == 0:
  13.         print('selected box 1')
  14.         x = random.choice(box1)
  15.         print('selected ' + x)
  16.         if box1.count(x) == 2:
  17.             print('match')
  18.             counter1 += 1
  19.         else:
  20.             print('NO match')
  21.         i += 1
  22.     if box == 1:
  23.         print('selected box 2')
  24.         x = random.choice(box2)
  25.         print('selected ' + x)
  26.         if box2.count(x) == 2:
  27.             print('match')
  28.             counter1 += 1
  29.         else:
  30.             print('NO match')
  31.         i += 1
  32.     if box == 2:
  33.         print('selected box 3')
  34.         x = random.choice(box3)
  35.         print('selected ' + x)
  36.         if box3.count(x) == 2:
  37.             print('match')
  38.             counter1 += 1
  39.         else:
  40.             print('NO match')
  41.         i += 1
  42. print('matches: ' + str(counter1) + ' total: ' + str(i) + ' chance: ' + str(counter1/i*100))
  43.  
RAW Paste Data