Recap: Telemetry Toolkit
Combine scope, default parameters, multiple return values, and try/except
Mission: Telemetry Toolkit
Build a small toolkit. Each function should work only with its parameters and return its result (good scope discipline).
safe_int(text, fallback=0): uses try/except to turntextinto an int. Ifint()fails, returnfallback. Thefallbackparameter has a default of0.summarize(numbers): returns three values: the total, the largest, and the smallest of a list of numbers.
In the main program, you have a list of readings (some are corrupted). Then:
- go through
readingsand usesafe_inton each to build a list callednumbers(corrupted readings become0) - print
Numbers:then that list - call
summarize(numbers), unpack the three values, and printTotal:,Largest:, andSmallest:
Output
Numbers: [10, 0, 25, 7, 0]
Total: 42
Largest: 25
Smallest: 0