2015-04-05 12:07:28 -03:00

20 lines
445 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 pick(self):
try:
position = random.randrange(len(self._balls)) # <3>
except ValueError:
raise LookupError('pop from empty BingoCage')
return self._balls.pop(position) # <4>