J
Without understanding very well the logic you are trying to create, the class Codigo has attributes that are not created when you invoke the method DiaDefinitivo. In fact, they have no attributes and no methods.A possible rewriting:class Codigo:
def __init__(self):
self.noche = 0
self.tarde = 0
self.mediodia = 0
self.mañana = 0
self.madrugada = 0
def Evaluacion(self, *, horaDiaUno=True, horaDiaDos=True, horaDiaTres=True):
a, b, c = horaDiaUno, horaDiaDos, horaDiaTres
if (a, b, c) == (True, True, True):
self.madrugada = 1
elif (a, b, c) == (False, True, True):
self.mañana = 1
elif (a, b, c) == (True, True, False):
self.mediodia = 1
elif (a, b, c) == (False, True, False):
self.tarde = 1
elif (a, b, c) == (True, False, True):
self.noche = 1
elif (a, b, c) == (True, False, False):
self.madrugada = 1
elif (a, b, c) == (False, False, False):
self.noche = 1
The arguments of the method Evaluación are invoked by name, for example: Codigo().Evaluación(horaDiaTres=False). By default, the three days are True. I don't know if it's right or not.An improvement to not have so many ifs, be using a dictionary:from enum import Enum
class HoraDia(Enum):
NOCHE = 0
TARDE = 1
MEDIODIA = 2
MAÑANA = 3
MADRUGADA = 4
class Codigo:
def init(self):
self.horaDia: HoraDia = HoraDia.NOCHE
def Evaluacion(self, *, horaDiaUno=True, horaDiaDos=True, horaDiaTres=True):
horas = {
(True, True, True): HoraDia.MADRUGADA,
(False, True, True): HoraDia.MAÑANA,
(True, True, False): HoraDia.MEDIODIA,
(False, True, False): HoraDia.TARDE,
(True, False, True): HoraDia.NOCHE,
(True, False, False): HoraDia.MADRUGADA,
(False, False, False): HoraDia.NOCHE,
}
self.horaDia = horas[(horaDiaUno, horaDiaDos, horaDiaTres)]
I know if it would fit you or not. Add in comments what you consider.