Is there a better way to structure my code | Sololearn: Learn to code for FREE!


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")

2/14/2021 5:35:56 PM

Marc-Olivier Auger

4 Answers

New Answer


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.


You can do if 10<=hour<=20 and 1<=day<=5:


It is can't be shortened anymore (Maybe I'm wrong, let's see what other's answer)


Awesome thanks guys for your time !!