1

How to fix this condition?

def do_something():
     print("Do Something !")
def do_nothing():
     print("Do Nothing !")
day=datetime.datetime.now().strftime("%A")
time=datetime.datetime.now().strftime("%H:%M")
start_time=int(time.split(":")[0])
end_time=int(time.split(":")[1])
## Monday Conditions
if day.lower()=="monday" and start_time==9 and end_time>10:
    do_nothing()
elif day.lower()=="monday" and start_time==9 and end_time>41:
    do_something()

on monday, i want to run correct conditions on time but even on correct time, this condition runs all the time:

if day.lower()=="monday" and start_time==9 and end_time>10:
    do_nothing()

im new to python

Submitted May 08th 2021 by Admin

Answers
0

Try switching 41 and 10 in the if statements:

if day.lower()=="monday" and start_time==9 and end_time>41: do_nothing()
elif day.lower()=="monday" and start_time==9 and end_time>10: do_something()

Admin | 4 months ago


0

let assume end_time = 50 so always end_time > 10 and end_time > 41

you can do this

if day.lower() == "monday" and start_time == 9 and end_time > 41: do_something()
elif day.lower() == "monday" and start_time == 9 and end_time > 10: do_nothing()

Admin | 4 months ago



Relevant Questions