Exercise 2 solution import re def to_f(m): f = float(m.group(1)) * 9 / 5 + 32 return f"{f:.1f}F" print(re.sub(r"(-?\d+(?:\.\d+)?)C\b", to_f, "Mon 20C, Tue -5C, Wed 21.5C, 3Cats")) # Mon 68.0F, Tue 23.0F, Wed 70.7F, 3Cats (All lines were run and printed exactly what is shown.) Explanation: when the replacement is a function, re.sub calls it with each match object and uses the string it returns. The group captures the signed, optionally decimal number, the function converts it, and the trailing \b stops "3Cats" being touched, because there is no word boundary between C and a.