+ 1

Why doesnt it output "closed"?

Python core 21.2 problem, test case #3 shows no output. hour = int(input()) day = int(input()) # your code goes here if day >= 1 and day <=5: if hour >= 10 and hour <= 21: print("Open") else: print("Closed")

25th Aug 2021, 3:38 AM
nabeer zahed chowdhury
nabeer zahed chowdhury - avatar
5 odpowiedzi
+ 3
nabeer zahed chowdhury The problem is with your else statement. The else clause should execute whenever any of the above if statements (chained) won't execute. You can make it work by combining all the conditions with the 'and' keyword instead of chaining it: if 0 < day < 6 and 9 < hour < 22: ... else: ... # I hope that this helps you with your query. Happy coding!
25th Aug 2021, 4:20 AM
Calvin Thomas
Calvin Thomas - avatar
+ 2
Delicate Cat yep, but in test case #3, it doesn’t satisfy the if statement therefore should go to else statement. But its not doing that Also, why does the chaining And not chaining if statements cause different outputs. Appreciate ur help
25th Aug 2021, 4:23 AM
nabeer zahed chowdhury
nabeer zahed chowdhury - avatar
+ 2
Well im not aware actually, but after you mentioned them, I found those online and probably I'll learn them adequetly in future... Thanks
25th Aug 2021, 4:32 AM
nabeer zahed chowdhury
nabeer zahed chowdhury - avatar
+ 1
Could you post the description of the assignment?
25th Aug 2021, 3:50 AM
你知道規則,我也是
你知道規則,我也是 - avatar
0
nabeer zahed chowdhury Hmm, you may have a look at the corrected version of your code: hour = int(input()) day = int(input()) print("Open" if 0 < day < 6 and 9 < hour < 22 else "Closed") # Note: I'm posting this assuming that you're aware of chained conditionals and the ternary statement in Python
25th Aug 2021, 4:28 AM
Calvin Thomas
Calvin Thomas - avatar