CS Unplugged activity
Creature Sorting: Real if Statements
If you did Creature Sorting,
you already know how AND, OR, and NOT work. Python uses the exact same
logic. The only thing that changes is the spelling: instead of the
AP-style AND, OR, NOT, Python writes and, or, not, in lowercase.
Everything else, including the inclusive OR and the way NOT only touches
what comes right after it, works identically.
A real if statement in Python looks like this:
if has_hat and not striped:
print("This one gets a ribbon.")
That line is only true (and only prints the ribbon message) for a creature that has a hat and isn’t striped. Same rules, real code.
Version history
- Loading commit history…