+ 2
Store is closed
hour = int(input()) day = int(input()) # your code goes here if day==1 or day==2 or day==3 or day==4 or day==5 and 10<=hour<=21: print("Open") else: print("Closed") if day==â1â or day==â2â or day==â3â or day==â4â or day==â5â and 10<=hour<=21: print("Open") else: print("Closed") When I write the first program the answer for 23 and day=2 will be open that is incorrect ! But when I write the second one with ââ the answer for 23 and 2 will be correct but not for others!!can anyone help me plz?
6 Answers
+ 3
Hi Mahdieh!
It's always better to separate logical operators using parenthesis. The reason is that is operator precedence. Here, and operator has higher precedence than or operator and rational operators( < > ==).
So, it needs to be like this
if(day == 1 or...) and (10 <= hour <= 21)
But, you can think about other easy ways to solve this challenge like using range() and so on.
+ 3
JUMP_LINK__&&__Python__&&__JUMP_LINK Learner Dear Python learner I tried your answer and It worked.thanks.
+ 2
Maybe you can use range() to check the day of week and hour of day. No guarantee though, hidden cases are part of the challenge.
if day in range( 1, 6 ) and hour in range( 10, 22 ):
# Open
else:
# Closed
P.S. Comparing either <day> (int) with string literals isn't what we're supposed to do. Except where we read <day> as string also - we don't use int() to convert input string into int.
+ 2
Ipang yes I saw other ways and tried them too but it was weired why this way doesnât answer.thank you for your help
+ 1
check it if you need
hour = int(input('Enter the Hour: '))
day = int(input('Enter the Day: '))
h = [x for x in range(10, 22)]
d = [x for x in range(1, 8)]
if (hour in h) and (day in d):
print('Open')
else:
print('Closed')
+ 1
Krishnam Raju M thank you Krishnam