0
Boolean Logic (debug)
Hey guys! can you please help me debug my code and explain why it has bug? ##the shop is Open around 10 to 21 o'clock. it opens only Monday to Friday except SAT and SUN. (the day of the week represented as 1 for Mon, 2 for Tue, etc.) #this is my code hour = int(input()) day = int(input()) if(hour >= 10 or hour < 21): if(day == 6 or day == 7): print("Closed") else: print("Open") # but the result goes like this: 9 1 Open 22 2 Open
20 Respostas
+ 9
And also, add an another else statement outside the nested if-else so if the first condition is False, it will print "Closed" .
hour = int(input())
day = int(input())
if(hour >= 10 and hour < 21):
if(day == 6 or day == 7):
print("Closed")
else:
print("Open")
else:
print("Closed")
+ 10
#Change your first condition
#Everything will be fine
#Try this
hour = int(input())
day = int(input())
if(hour <= 10 or hour > 21) or (day == 6 or day == 7):
print("Closed")
else:
print("Open")
+ 5
9 is less than 21 so it meets that check. You should use AND instead of OR in the check (or just shorten to: if 10 <= hour < 21)
+ 5
Yamo Anyways now that the problem is solved, let us just be thankful to those who helped as they enable us to solve it. āŗš
+ 4
thank you guys!
i should practice more in boolean logic
+ 4
Yeah thank you very much guys! I want to enhance my coding skils more in boolean logic
+ 3
Slick Oh, I got wrong in that part, Thanks for that correction!
+ 2
yeah cause 6 doesnt equal 7.
your check only passes if the number is equal to 6 AND 7, wich is impossible
this is where you'd use OR
+ 2
Just use the first one you had that worked after the tweak. It was more readable anyways
+ 2
Here the complete program using IntEnum machinery for validation and operate.
Also importable as module
https://code.sololearn.com/cdUXQjFbBXhS/?ref=app
+ 1
Thank you! This is very confusing š
+ 1
Simba that's no output
+ 1
Simba
13
6
Open
#fail
+ 1
slick already help me to debug Simba
+ 1
That one uses OR so if one passes, it moves on. You need them both to pass, so use AND
+ 1
Simba hahahahaš
+ 1
Slick but it requires a conditional input so what is best for it?
+ 1
I had to...
https://code.sololearn.com/ckg3cKNEeeWK/?ref=app
0
hour = int(input())
day = int(input())
if(hour >= 10 and hour < 21):
if(day == 6 and day == 7):
print("Closed")
else:
print("Open")
else:
print("Closed")
#but
13
6
Open
#there's more fail on my code
0
hour=int(input())
day=int(input())
if(hour>=10 or hour<21):
if(day>=1 or day<=5):
print("open")
else:
print("closed")