Project: Word Frequency Counter Objective:
Create a Python script that counts the frequency of words in a given text using dictionaries, conditional sentences, loops, and recursive functions.
Instructions:
-
Create a function that takes a string of text as input.
-
Use a dictionary to store the frequency of each word in the text.
-
Use conditional sentences to handle special cases (e.g., empty input).
-
Use loops to iterate over the words in the text.
-
Use a recursive function to process the text and update the word frequency dictionary
This project demonstrates the following concepts:
.Dictionaries: A dictionary (frequency) is used to store the frequency of each word in the text.
.Conditional sentences: The script uses an if statement to handle the base case of empty input.
.Loops: The for loop is used to iterate over the items in the word frequency dictionary and print the word and its count.
.Recursive functions: The process_words() function is a recursive helper function that processes each word in the text. It updates the word frequency dictionary recursively until all words are processed.
The script takes a string of text as input, removes punctuation, converts it to lowercase, and splits it into words. It then uses a recursive function to process each word and update the word frequency dictionary. Finally, it prints the word frequency dictionary, showing each word and its count.