Files
example-code-2e/interfaces/bingo.py
2014-10-14 14:26:55 -03:00

20 lines
437 B
Python

import random
from tombola import Tombola
class BingoCage(Tombola): # <1>
def __init__(self, items):
self._balls = list(items) # <2>
def load(self, items):
self._balls.extend(items)
def pop(self):
try:
position = random.randrange(len(self._balls)) # <4>
except ValueError:
raise LookupError('pop from empty BingoCage')
return self._balls.pop(position)