Exercise 6: Total a List of Messy Values — Possible Solution ==================================================================== raw = ["12", "x", "7.5", "", "3", "1e2", "n/a"] total = 0.0 skipped = [] for item in raw: try: value = float(item) except ValueError: skipped.append(item) continue total += value print("total:", total) print("skipped:", skipped) Example run: total: 122.5 skipped: ['x', '', 'n/a'] WHY THIS WORKS AS AN ANSWER ------------------------------ float() raises ValueError for text it cannot read, which jumps to the except block. There the item is remembered and continue ends the pass, so total += value is never reached with a missing value (value would be missing, or would still hold the previous item's number). Note that float accepts '1e2' (scientific notation, 100.0) as a number, which may surprise you: the converter decides what counts as valid, not your idea of a number. The empty string and 'n/a' fail and are reported. 12 + 7.5 + 3 + 100 = 122.5.