Week 1
Conditionals
A program can look at a value and take one path or another.
A conditional is a fork. If a test is true, one block runs. Elif is another test, checked only when the earlier ones were false. Else is what remains. You can combine tests with and and or. And means both. Or means at least one.
The order of the tests matters. A more specific test has to come before a broader one, or the broad one swallows it. Match is another way to choose among exact values. It is the same idea as a chain of equality tests.
A fresh example: a cloakroom that charges nothing for a coat, a small fee for a bag, and a larger fee for anything else. Say the coat rule first. If you say 'anything else' first, coats never get their own price.
Problems
- Deep ThoughtCompare text, ignoring how it is capitalized and whether a space or a hyphen sits in the middle.
- Home Federal Savings BankLook at the start of a greeting, not the whole sentence.
- File ExtensionsLook at the ending of a file name.
- Math InterpreterSplit one line into a number, a sign, and another number, then do that one operation.
- Meal TimeTurn a clock time into a number of hours, then see which meal window it sits in.