and / or: Double Checks ๐ข
What if a decision depends on two things at once? Meet and and or.
and โ both sides must be True:
height = 145
has_ticket = True
if height >= 140 and has_ticket:
print("Climb aboard! ๐ข")
Tall enough but no ticket? No ride. Ticket but too short? No ride. It takes both.
or โ only one side needs to be True:
day = "Saturday"
if day == "Saturday" or day == "Sunday":
print("WEEKEND! ๐")
An easy way to remember: and is picky, or is generous.
Your mission
Build the gate for a rollercoaster!
- Make three variables:
height(a number),has_ticket(True or False), andday(a day of the week, in quotes) - Use
andin anifto let riders on only when they're tall enough and have a ticket โ with anelsefor the ones who don't make it - Then use a second
ifwithorto print a bonus message whendayis "Saturday" or "Sunday"
Your code
Press โถ Run to see what your code does!