BookBot is a simple Python program that analyzes text files (like classic books) and provides a report on the word count and character frequency.
- Reads a
.txt
file. - Counts the total number of words.
- Counts the occurrences of each character (case-insensitive).
- Generates a simple, human-readable report.
bookbot/
│
|
│── frankenstein.txt # Sample text file
│
└── main.py # Main program logic
- Read the file – The program loads the text file
- Word count – It counts the total number of words.
- Character frequency – It counts how many times each character appears.
- Report – Prints the results to the console.
Example of generated report:
--Begin report on frankenstein.txt
77986 words found in the document
The 'a' character was found 48622 times
The 'b' character was found 9132 times
...
--End report--
main()
– The entry point that runs the analysis.get_text(path)
– Reads and returns file contents.word_count(text)
– Counts the words in the text.char_count(string)
– Counts occurrences of each character (lowercased).print_report(text)
– Generates and prints the summary report.
- Place your
.txt
file inside thebooks
folder. - Update the
path
variable inmain()
to point to your file. - Run the program:
python main.py
- Python 3.6+
- A
.txt
file to analyze (UTF-8 encoded)
- Character counting includes spaces, punctuation, and special characters.
- Reports are printed directly to the terminal.