d08 · Parse a quantity (~5 min)
Parsing strings. Edit drills.py. Standard library only; no model calls, no API key.
def parse_quantity(value):
Return a positive whole number from a messy tool input.
Accept: an int; a float or string holding a whole number (3.0, "3", " 3 ", "3.0"); a string with a number followed by whitespace and words ("3 units"); full-width digits ("3"). Raise ValueError for anything else, including 0, negatives, non-whole numbers (2.5, "2.5"), booleans, None, "", "three" and "3abc".
Failure messages are enough to go on, so leave the tests unread until you submit.