+ 2
Hi I need Help with Boolean logic 2 coding challenge. The code below works with all but one case and I can't figure it out.
hour = int(input()) day = int(input()) # your code goes here #You need to create a program that outputs whether a store is Open or Closed, based on the hour and the day of the week. #The store is open on all days from 10 to 21, except Saturday and Sunday. #You need to take the hour and the day of the week as input. #The day of the week is represented as an integer (1 for Monday, 2 for Tuesday, etc.) #Sample Input: #15 #4 if day >= 1 and day <= 5: if hour > 9 and hour < 21: print("Open") else: print("Closed")
8 odpowiedzi
+ 3
if day >= 1 and day <= 5:
if hour >=10 and hour <= 21:
print("Open")
else:
print("Closed")
else:
print("Closed")
+ 2
From the description of oppening hours should be
if hour >= 10 and hour <= 21:
+ 1
If you input day in the range 1-5 and hour=21 your code will output nothing. But it must output "open".
Also if the day is in the range 1-5 and the hour is not in the range 10-21 then your code will output nothing. It should output "closed".
I think it is the problem with your test case.
+ 1
hour = int(input())
day = int(input())
# your code goes here
if hour >= 10 and hour <=21 and day !=6 and day !=7:
print("Open")
else:
print("Closed")
0
Thank you but it still is not working even with JaScript's code. Also if the hour is at 21 wouldn't it be Closed and not Open?
0
I think you forgot to add an else statement inside.
hour = int(input())
day = int(input())
if day >= 1 and day <= 5:
if hour >= 10 and hour <= 21:
print('Open')
else:
print('Closed')
else:
print('Closed')
0
Thank you all. Didn't know I needed an else statement inside. Does this mean with nested if statements I also need nested else statements?
0
It still depends on the problem.
if (day >= 1 and day <= 5) and (hour >= 10 and hour <= 21) :
print('Open')
else:
print('Closed')
In shorter code, it will be like this☝.