I'm trying to create a code for light consumption and I want that if the day introduced is on the weekend , to show "Estás en el tramo valle, aprovecha para hacer lavadoras!" and break the loop but if the day is on the weekday, to check the hour and then, print the different messages depending on the hour.
If the day is on the weekday, it works fine, but if the day is on the weekend, I get the 2 messages, the one saying "Estás en el tramo valle..." and the other checking the hour.
I would like the "for h in hora" part to be indented on the upper part but when I do so, I get the message duplicated 6 times (one per if function)
Could you help me? Is there any function to do this?
CodePudding user response:
It would be easier to answer if you had your code pasted, but I can still describe what you need to do.
Create a variable such as weekend and set it to false. Before each break of the first for loop, set weekend to True. Before the second for loop, put a for loop checking if weekend is false
weekend = False
for x in dia:
if dia == '...':
print('...')
weekend = True
break
if dia == '...':
print('...')
weekend = True
break
if not weekend:
{second for loop}