Skip to content

Instantly share code, notes, and snippets.

@echiesse
Created November 23, 2017 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save echiesse/de15c9c501173bb49bf2ebfda7eaec4a to your computer and use it in GitHub Desktop.
Save echiesse/de15c9c501173bb49bf2ebfda7eaec4a to your computer and use it in GitHub Desktop.
class Combustivel:
def __init__(self, nome, preco, texto):
self.nome = nome
self.preco = preco
self.texto = texto
gasolina = Combustivel(
nome = "gasolina",
preco = 1,
texto = "-Recomendamos GASOLINA-"
)
alcool = Combustivel(
nome = "alcool",
preco = 1,
texto = "--Recomendamos ÁLCOOL--"
)
def devoUsarAlcool(preco_alcool, preco_gasolina):
return (preco_alcool / preco_gasolina) < 0.70
def escolherCombustivel(alcool, gasolina):
return alcool if devoUsarAlcool(alcool.preco, gasolina.preco) else gasolina
def limparCampo(text_box, conversor):
ret = None
try:
ret = conversor(str(text_box.get()))
except:
pass
return ret
def limparCampos():
return map(lambda tb: limparCampo(tb, float), [text_box_alcool, text_box_gasolina])
def mensagem(*args):
alcool.preco, gasolina.preco = limparCampos()
lb_mensagem["text"] = escolherCombustivel(alcool, gasolina).texto \
if alcool.preco != None \
else "Valores informados invalidos"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment