Store is closed | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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?

29th Oct 2021, 11:42 AM
Mahdieh Zarbazou
Mahdieh Zarbazou - avatar
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.
29th Oct 2021, 12:33 PM
Python Learner
Python Learner - avatar
+ 3
JUMP_LINK__&&__Python__&&__JUMP_LINK Learner Dear Python learner I tried your answer and It worked.thanks.
29th Oct 2021, 12:55 PM
Mahdieh Zarbazou
Mahdieh Zarbazou - avatar
+ 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.
29th Oct 2021, 12:28 PM
Ipang
+ 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
29th Oct 2021, 12:57 PM
Mahdieh Zarbazou
Mahdieh Zarbazou - avatar
+ 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')
29th Oct 2021, 1:50 PM
Krishnam Raju M
Krishnam Raju M - avatar
+ 1
Krishnam Raju M thank you Krishnam
29th Oct 2021, 2:16 PM
Mahdieh Zarbazou
Mahdieh Zarbazou - avatar