+ 1
You need to create a program that outputs whether a store is Open or Closed, based on hour and day
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.) https://code.sololearn.com/c3C1hd9ky5ft/?ref=app https://code.sololearn.com/c3C1hd9ky5ft/?ref=app
19 Respuestas
+ 6
#You can use "or" operator to check the hours
hour = int(input())
day = int(input())
if ((hour<10 or hour>21) or (day>= 6)):
print('Closed')
else:
print('Open')
+ 3
hour, day = int(input()), int(input())
print("Open" if 10 <= hour < 21 and day < 6 else "Closed")
+ 3
hour = int(input())
day = int(input())
if (hour>=10) and (hour<=21) and (day<=5):
print("Open")
else:
print("Closed")
+ 2
hour = int(input())
day = int(input())
# your code goes here
hours = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]
days = [1, 2, 3, 4, 5]
def store(hour, day):
if hour in hours and day in days:
print("Open")
else:
print("Closed")
store(hour, day)
+ 1
If you did that, you would have realized that your logic makes no sense.
"hour<10 and hour>21" will ALWAYS be false. You simply cannot have an integer which is smaller than 10 and bigger than 21 at the same time.
0
Tell me....where I did mistake...Code is not working for some test cases
0
The first part of your condition always evaluates to 'false', check your operstors.
The second part evaluates to day >= 6. Again check your operators "6 or 7" will be just 6
0
Yah, I already do that but I had failed in another test case.
0
@Puneetha Akula , thank you for sharing your solution!
In my initial attempt of this question, I wrote the code below, which turned out to be wrong (or at least half right...lol).
Could someone kindly elaborate on why my code is wrong? I know the answer to this question has already been provided. I just want to have a better understanding.
hour = int(input())
day = int(input())
if ((hour >=10 or hour <=21) or (day >= 1 or day <= 5)):
print("Open")
else:
print("Closed")
0
a=int(input("enter the day of the week you want to visit"))
b=int(input("enter the time you want to visit"))
if (1<a<=5) and(10<b<21):
print("open")
else :
print ("closed")
0
hour = int(input())
day = int(input())
if (hour>=10) and (hour<=21) and (day<=5):
print("Open")
else:
print("Closed")
0
hour = int(input())
day = int(input())
if (hour == 10 or hour <= 21) and (day == 1 or day <= 5 ):
print("Open")
else:
print("Closed")
0
hour = int(input())
day = int(input())
if (hour == 10 or hour <= 21) and (day == 1 or day <= 5 ):
print("Open")
else:
print("Closed")
This passes all the tests however it is still wrong. If the code tested for 9AM it should fail but passes because the OR hour is <=21.
0
hour = int(input())
day = int(input())
if hour >= 10 and hour <= 21 and day <=5:
print("Open")
else:
print("Closed")
0
hour=int(input('Enter the hour: '))
print('Enter day in following number: \n 1 for Monday \n 2 for Tuesday \n 3 for Wednesday \n 4 for Thursday \n 5 for Friday \n 6 for Saturday \n 7 for Sunday')
day=int(input('Enter the day you want: '))
if(day!=6 and day!=7):
if(hour>=10 and hour<=21):
print('opened')
else:
print('closed')
else:
print('closed')
0
hour = int(input())
day = int(input())
if hour >= 10 and hour <=21 and day >=1 and day <=5:
print("Open")
else:
print("Closed")
0
I cant solve it
- 1
hour = int(input())
day = int(input())
if (hour >= 10 and hour <= 21) and (day >= 1 and day <= 5):
print("Open")
else:
print("Closed")
This would be the most correct answer because all possible inputs correctly output.
- 9
SoloLearn, where you don't learn anything because people give you the correct answer instead of actually helping. Lmao