And, Or, Not: Two Questions!
Can one if check two questions at once?
Real Python code
This is the code from the video. Read it out loud like a recipe, one line at a time!
sunny = True
homework_done = True
raining = False
if sunny and homework_done:
print("Off to the park!")
if not raining:
print("No umbrella needed!")
Quiz time!
Sunny, but homework not done. Does Bit go?
sunny = True
homework_done = False
or: one yes is enough
Pizza tonight?
Yes! Bit is happy.
Pasta tonight?
Yes! Bit is happy too.
Pizza and pasta?
Two yeses? Still happy. Or is fine with both.
Neither one?
Both answers are no, so or says no.
Oops: and was too strict
Bit's rule: and
- Snack if the fruit is an apple
- AND the fruit is a banana
- One fruit can't be both!
- Always no. No snack, ever
Fixed rule: or
- Snack if the fruit is an apple
- OR the fruit is a banana
- Apple? Yes, snack time!
- Banana? Yes, snack time!
With and, every answer must be yes. With or, one is enough!
Try it yourself!
Write three house rules on paper using and, or and not, then test each one with yes and no answers.
Bit is working on the next one: Loops with a stop sign