Exercise 3 solution import re def count_literal(needle, text): return len(re.findall(re.escape(needle), text)) text = "Price 1.5, price 1x5, code (a+b) and (a+b) again, 1.5 end" for needle in ["1.5", "(a+b)", "a+b"]: print(needle, count_literal(needle, text), text.count(needle)) print(len(re.findall("1.5", text))) # 1.5 2 2 # (a+b) 2 2 # a+b 2 2 # 3 (All lines were run and printed exactly what is shown.) Explanation: re.escape makes every special character literal, so the escaped searches agree with str.count. The unescaped 1.5 treats the dot as "any character" and also matches 1x5, giving 3. For fixed text like this, str.count is the better tool: it is shorter and has no syntax to get wrong.