Advertisement
ssoni

pickle.py

Jan 12th, 2024
927
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. import random
  2.  
  3. def main():
  4.  
  5.     winsA = 0
  6.     winsB = 0
  7.  
  8.     for x in range(1000):
  9.         scoreA = 7
  10.         scoreB = 1
  11.  
  12.         while (scoreA < 11 and scoreB < 11) or abs(scoreA-scoreB)<2:
  13.             x = random.random()
  14.             if x>.5:
  15.                 scoreA += 1
  16.             else:
  17.                 scoreB += 1
  18.  
  19.         print(f'{scoreA}-{scoreB}')
  20.  
  21.         if scoreA > scoreB:
  22.             winsA += 1
  23.         else:
  24.             winsB += 1
  25.  
  26.     winPct = round(winsA/(winsA+winsB)*100)
  27.     print(f'With a 7-1 lead, player A wins {winPct}% of the simulations.')
  28.  
  29. main()
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement