text.count('cat') also counts 'catalog'. Write count_word(text, word) counting only whole-word, case-insensitive occurrences using \b boundaries and re.IGNORECASE — and escape the word with re.escape in case it carries regex metacharacters.count_word('Cat catalog CAT scatter', 'cat')2
Only the standalone 'Cat' and 'CAT' count.
rf'\b{re.escape(word)}\b'.
len(re.findall(...)) counts.