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?
10/29/2021 11:42:18 AM
Mahdieh Zarbazou
6 Answers
New AnswerHi 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.
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.
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
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')