Created
September 17, 2012 16:19
-
-
Save mcosta/3738275 to your computer and use it in GitHub Desktop.
Código inicial usado na Lista de Exercícios 1 do curso "Objetos Pythonicos" de Luciano Ramalho, Oficinas Turing.
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
# coding: utf-8 | |
""" | |
Código inicial usado na Lista de Exercícios 1 do curso | |
"Objetos Pythonicos" de Luciano Ramalho, Oficinas Turing. | |
""" | |
class Contador(object): | |
'Classe contador' | |
def __init__(self): | |
total = 0 | |
self.totais = {} | |
def contar(self, item): | |
qtd = self.totais.get(item, 0) + 1 | |
self.totais[item] = qtd | |
def contagem(self, item): | |
return self.totais[item] | |
class ContadorAmigavel(Contador): | |
'Classe contador amigavel' | |
def contagem(self, item): | |
if item not in self.totais: | |
return 0 | |
else: | |
return self.totais[item] | |
class ContadorTotalizador(Contador): | |
'Classe contador totalizador' | |
def __init__(self): | |
self.total = 0 | |
super(ContadorTotalizador, self).__init__() | |
def contar(self, item): | |
# Contador.contar(self, item) | |
super(ContadorTotalizador, self).contar(item) | |
self.total += 1 | |
def porcentagem(self, item): | |
return round((float(self.contagem(item)) / self.total) * 100, 1) | |
class ContadorTotalizadorAmigavel(ContadorTotalizador, ContadorAmigavel): | |
'Classe TotalizadorAmigavel' | |
def __init__(self): | |
super(ContadorTotalizadorAmigavel, self).__init__() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment