This question is for learning purposes, it serves little practical uses.
TextStat is a class that has a method count_words tha
TextStat
count_words