Build a Text Analyzer with Python
Level: Beginner
Project Skills Needed
This project covers the following concepts. Click any link to learn more about them if you're unfamiliar.
input() function | print() function | strings |lists| dictionaries | if-else conditionals
Project Description
This program takes a block of text provided by the user, analyzes it, and provides useful statistics about the text to the user.
How the Project Works
The program starts by prompting the user to enter some text in the terminal:
The user pastes some text.
After the user presses Enter, they get different statistics about the submitted text: the number of words, sentences, and characters, the most frequent words used in the text, the average word length, and the average sentence length.
Prerequisites
Required Libraries: No libraries are required.
Required Files: No files are required.
IDE: You can use any IDE on your computer to code the project.
Danger Zone
Feel free to use the hints below for help:
Once you code the project, compare it with our solution below:






Ardit, this is superb exercise, not only the logic you have built to derive text statistics but how we write the code/program is absolutely amazing. Thanks!! This is how I want to write the code. I "cleaned" my dev.py and re-built and re-formatted entire code. Re-do is also part of learning process.
def length_analyser(a):
b=len(a)
c=len(a.split(' '))
d=a.count(".") + a.count("?") + a.count("!")
test1=a.split(' ')
n=0
for i in test1:
n+=len(i)
return b ,c,d,n/len(test1),c/d
def freq_word(a):
test={}
test1=a.split(' ')
for i in test1:
test[i]=test1.count(i)
word=max(test,key=test.get)
return word , test[word]
x= input("enter a bloxk of text for analysis:")
char_count,word_count,line_count,avg_word_len,avg_sent_len=length_analyser(x)
z,f=freq_word(x)
print("Total number of charaters {}".format(char_count) )
print("Total number of words {}".format(word_count) )
print("Total number of lines {}".format(line_count) )
print("Most frequest word used is {} . it is used {} times".format(z,f) )
print("Average word length is {}".format(avg_word_len) )
print("Average sentence length is {}".format(avg_sent_len) )