+ 1

Is there a better way to structure my code

Is there a better way (shorter) to code the boolean logic if-and in this code ; hour = int(input()) day = int(input()) # your code goes here if hour>=10 and hour<=20 and day>=1 and day<=5 : print ("Open") else : print ("Closed")

14th Feb 2021, 5:35 PM
Marc-Olivier Auger
Marc-Olivier Auger - avatar
4 odpowiedzi
+ 8
Marc-Olivier Auger as ∆BH∆Y already mentioned: your code is ok. an alternative way of doing the conditional expression could be to use range like: if hour in range(10,20+1) and day in range(1,5+1): but this is not shorter or faster, maybe the readability is a bit better. but nothing what really matters.
14th Feb 2021, 5:56 PM
Lothar
Lothar - avatar
+ 4
You can do if 10<=hour<=20 and 1<=day<=5:
14th Feb 2021, 5:57 PM
Angelo
Angelo - avatar
+ 1
Awesome thanks guys for your time !!
14th Feb 2021, 11:36 PM
Marc-Olivier Auger
Marc-Olivier Auger - avatar