Last active
August 29, 2015 14:08
-
-
Save gabicavalcante/3b99844e7ac2a0740e47 to your computer and use it in GitHub Desktop.
Código que simula o jogo Bingo com uma cartela.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import random | |
import sys | |
import pdb | |
class Cartela: | |
def __init__(self): | |
self.numeros = [[],[],[],[]] | |
self.numerosmarcados = 0 | |
for x in range(0,4): | |
for y in range(0,4): | |
l = range(1, 76) | |
self.numeros[x].append(random.choice(l)) | |
def existeNumero(self, numero): | |
for x in range(0,4): | |
return([num for num in self.numeros if numero == x]) | |
def exibeCartela(self): | |
print "\n" | |
print "=" * 3*10 | |
for x in range(0,4): | |
print "| %4d | %4d | %4d | %4d |" % (self.numeros[0][x],self.numeros[1][x], \ | |
self.numeros[2][x],self.numeros[3][x]) | |
print "=" * 3*10 | |
class Bingo: | |
def __init__(self): | |
self.carta = Cartela() | |
self.restantes = range(1,76) | |
def removeRestante(self, numero): | |
self.restantes = filter(lambda arg:arg != numero,self.restantes) | |
for cartela in self.carta.numeros: | |
if self.carta.existeNumero(numero): | |
cartela.numerosmarcados += 1 | |
def sorteia(self): | |
return(random.choice(self.restantes)) | |
def main(): | |
bingo = Bingo() | |
# simulando um bingo | |
while bingo.restantes: | |
numeroSorteado = bingo.sorteia() | |
bingo.removeRestante(numeroSorteado) | |
bingo.carta.exibeCartela() | |
print "Faltavam %d" % (len(bingo.restantes)) | |
for cartela in bingo.carta.numeros: | |
if bingo.carta.numerosmarcados == 25: | |
print " ---- " | |
print "BATEU" | |
print "Faltavam %d" % (len(bingo.restantes)) | |
print bingo.restantes | |
bingo.carta.exibeCartela() | |
sys.exit() | |
#Executando o aplicativo se for chamado diretamente | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment