Exit
  1. Learn
  2. Check
  3. Solve
  4. Reflect

Two questions at once

A fairground ride says: you must be tall enough and have a ticket. Both must be true to get on. That joining word is and.

Sometimes one is enough. A shop gives a discount to students or to people over 60. That joining word is or: the answer is true when at least one of the questions is true. Both being true also counts.

And: needs every part true.
Or: needs at least one part true.
In code
can_ride = tall and has_ticket
discount = student or senior

Not, and brackets

The word not flips an answer: true becomes false, and false becomes true. Use it for rules like "divisible by 4, but not by 100".

When you mix and with or, use brackets to show what goes with what, just like in arithmetic. The leap year rule is a good example: a year is a leap year if it divides by 4 but not by 100, or if it divides by 400.

Mixing and with or? Use brackets to make the grouping clear.
In code
by4 = year % 4 == 0
by100 = year % 100 == 0
by400 = year % 400 == 0
leap = (by4 and not by100) or by400
Is 1900 a leap year?
year: 1900
0
by4: True
1
by100: ?
2
by400: ?
3
leap: ?
4
line
by4
True

1900 divides evenly by 4, so by4 is true.

Move 1 of 4