1
I’m running some tests and the code seems to be correct logically, but when I use an example, "what day is it today?" as self.phrase it only returns me the first if (of the hours), if I put as self.phrase = "What day of the week is today?" the same mistake happens, where I’m missing?
def about_time(self):
temp_atual = datetime.datetime.now()
if 'são' or 'sao' in self.frase:
print("Agora são " + str(temp_atual.hour) + " horas, " + str(temp_atual.minute) + " minutos e " + str(temp_atual.second) + " segundos.")
elif 'dia' and 'hoje' in self.frase:
print("Hoje é dia " + str(temp_atual.day) + "/" + str(temp_atual.month) + "/" + str(temp_atual.year))
elif 'dia da semana' in self.frase:
dia = temp_atual.isoweekday()
if dia == 1:
dia = "segunda-feira"
if dia == 2:
dia = "terça-feira"
if dia == 3:
dia = "quarta-feira"
if dia == 4:
dia = "quinta-feira"
if dia == 5:
dia = "sexta-feira"
if dia == 6:
dia = "sábado"
if dia == 7:
dia = "domingo"
print("Hoje é " + dia)
This is wrong
'são' or 'sao' in self.frase
, would have to be'são' in self.frase or 'sao' in self.frase
... this too is wrong'dia' and 'hoje' in self.frase:
, should be'dia' in self.frase and 'hoje' in self.frase:
– Guilherme Nascimento
can’t I pass two parameters of a made in the case of "in self.frase"? I thought I could, so it would be simpler. But thank you!
– dfop02
That’s not the point, the point is that OR and AND are logical operators, they don’t work within
in
, what this between them are separate things, ie before theOR
is a check, after the OR is another check, the same goes for AND, only it changes only the behavior, but still the logical operations are separated.– Guilherme Nascimento