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 Auger4 Answers
New AnswerMarc-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.
It is fine...it can't be shortened anymore (Maybe I'm wrong, let's see what other's answer)
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message