Advertisement
dougbaker45

Bingo

Aug 15th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.52 KB | None | 0 0
  1. import random
  2. drawcount = 0
  3. bingo = 'no'
  4. wins = {}
  5. wincount = 0
  6. callout = 9999
  7. global drawlist
  8. from timeit import default_timer as timer
  9. start = timer()
  10.  
  11. def makecards():
  12.     global cards
  13.     global drawlist
  14.     global drawround
  15.     cards = []
  16.     while len(cards) < 90:
  17.          cards.append(random.sample(range(1, 33), 12))
  18.     drawround = 0
  19.     drawlist = []
  20.  
  21. def bingocheck():
  22.     cardnum = 0
  23.     global bingo
  24.     for card in cards:
  25.         cardnum += 1
  26.         if len(card) == 0:
  27.             bingo = 'yes'
  28.  
  29. def draw():
  30.         global drawcount
  31.         global drawround
  32.         global drawlist
  33.         drawnum = random.randint(1, 32)
  34.         if drawnum not in drawlist:
  35.             #print (drawnum)
  36.             drawlist.append(drawnum)
  37.             drawcount += 1
  38.             drawround += 1
  39.             for card in cards:
  40.                 if drawnum in card:
  41.                     card.remove(drawnum)
  42. def win():
  43.     global wins
  44.     global bingo
  45.     global wincount
  46.     if drawround in wins:
  47.         wins[drawround] += 1
  48.     else:
  49.         wins[drawround] = 1
  50.     bingo = 'no'
  51.     wincount += 1
  52.  
  53. def status():
  54.     global wincount
  55.     global callout
  56.     if wincount > callout:
  57.         current = timer()
  58.         print (('Percent', wincount / 100000000))
  59.         print ('Time :' , (current - start))
  60.         callout += 10000
  61.  
  62.  
  63. def game():
  64.     makecards()
  65.     while bingo != 'yes':
  66.         draw()
  67.         bingocheck()
  68.     win()
  69.     status()
  70.  
  71. for i in range(100000000):
  72.     game()
  73. print (wins)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement