Sentinels and validation
12-minute lesson · module-iteration-03
You are previewing this course as a guest
Read anything and run any exercise you like. It all runs in your own browser, so nothing here is saved: no XP, no progress, and the AI tutor needs an account. Sign in and your work starts counting.
Sentinels and validation
12-minute lesson · module-iteration-03
- Use a sentinel value to terminate a `while` loop.
- Validate input by re-prompting until it meets a condition.
- Track running totals across an iteration.
Source attribution
Status: adapted
How to Think Like a Computer Scientist: Interactive Edition — source · More About Iteration / Validating input / The 3n+1 Sequence
Adaptation notes. Reading rewritten in our voice. Pyodide can't easily ask for live input, so the exercise reads from a pre-defined list to simulate sentinel input.
License notes. Verify chapter-level license metadata on Runestone before copying any text verbatim. This lesson contains no verbatim quotations.