Lite / Building Machines That Respond / Week 5
Week 5: Conditional statements
This week you will
- Use if / elif / else to choose an action from a measured value.
- Combine conditions with and, or and not to express a safety interlock.
- Choose boundary tests from a specification and use them to find a < versus <= bug.
Lessons
- Decisions from measurements: if, elif, else · about 35 min
A battery charger must refuse to charge below 0 °C and above 45 °C. How does a program choose between three actions? - and, or, not: safety interlocks in code · about 35 min
A press may run only if the guard is shut, an operator is present and there is no fault. Can one line of Python say all that? - Test the edges: boundary values · about 35 min
Two versions of a charger rule pass every test at 20 °C. One damages the battery at exactly 45 °C. Which test would have caught it?