def playBingo(): calls = generateCalls() num_calls = 0 card = createBingoCard() displayBingoCard(card) while True: #play until there is a winner new_call = calls.pop() print "New call:", new_call call_l = new_call[0] call_n = int(new_call[1:]) num_calls += 1 if call_n in card[call_l]: print "The number is on your card." # card[call_l] is a list; switch call_n value from that list with 0 # n is a location of that value in the list for n, v in enumerate(card[call_l]): if v == call_n: card[call_l][n] = 0 displayBingoCard(card) if checkWinner(card): print "WIN!" break else: print "Not on your card!" print "Number of calls:", num_calls return num_calls
def main(): from ex138_create_bingo_card import displayBingoCard card1 = {'b':[1,1,1,1,0], 'i':[1,1,3,0,1], 'n':[1,1,0,1,1], \ 'g':[1,0,5,1,1], 'o':[0,9,9,9,1]} print "diagonal:" displayBingoCard(card1) print "Winner!" if checkWinner(card1) else "Loser!" card2 = {'b':[1,1,1,1,0], 'i':[1,1,3,1,0], 'n':[1,1,1,1,0], \ 'g':[1,1,5,1,0], 'o':[1,9,9,9,0]} print "horizontal:" displayBingoCard(card2) print "Winner!" if checkWinner(card2) else "Loser!" card3 = {'b':[1,1,1,1,0], 'i':[1,1,3,1,1], 'n':[0,0,0,0,0], \ 'g':[1,1,5,1,1], 'o':[1,9,9,9,1]} print "vertical:" displayBingoCard(card3) print "Winner!" if checkWinner(card3) else "Loser!" card4 = {'b':[1,1,1,1,0], 'i':[1,0,3,1,1], 'n':[1,1,1,1,0], \ 'g':[1,0,5,1,1], 'o':[1,9,9,9,1]} print "not a winner:" displayBingoCard(card4) print "Winner!" if checkWinner(card4) else "Loser!"