Question

Write a text analyzer program using Python. The program should prompt the user for text to...

Write a text analyzer program using Python.

The program should prompt the user for text to analyze using the following prompt:

Please enter text to analyze or press ENTER (without text) to exit:

If the following text is input into by the user:

Fog everywhere. Fog up the river, where it flows among green

aits and meadows; fog down the river, where it rolls deified among

the tiers of shipping and the waterside pollutions of a great (and

dirty) city. Fog on the Essex marshes, fog on the Kentish heights.

Fog creeping into the cabooses of collier-brigs; fog lying out on

the yards and hovering in the rigging of great ships; fog drooping

on the gunwales of barges and small boats. Fog in the eyes and

throats of ancient Greenwich pensioners, wheezing by the firesides

of their wards; fog in the stem and bowl of the afternoon pipe of

the wrathful skipper, down in his close cabin; fog cruelly pinching

the toes and fingers of his shivering little apprentice boy on deck.

Chance 23 people on the bridges peeping over the parapets into a

nether sky of fog, with fog all round them, as if they were up in a

balloon and hanging in the misty clouds.

The program will output:

Count of characters: 901

Count of spaces: 163

Count of digits: 2

Count of letters: 715

Count of sentences: 6

Please enter text to analyze or ENTER (without text) to exit:

0 0
Add a comment Improve this question Transcribed image text
Answer #1

It is a type of fundamental question in python. Following is the code, which works perfectly with any type of paragraph and will give you the correct analysis.

You can copy this code and paste in your python terminal /shell /jupyter-notebook /online compiler etc.  

NOTE: Python uses indentation to identify whether a statement is under a for loop, while loop or inside an if-else statement. Be careful while pasting and running the code.

" # " symbol is used to provide comments in the code.

-------------------------------------------------------------------------------------------------------------------------------------------------------------

while True: #starting a while loop so that unless user will not press Enter key, code will keep analyzing new inputs
  

str1 = input("Please enter text to analyze or press ENTER (without text) to exit: ")

if str1 == "" :   
exit()
  

characters = 0   
space = 0
Sentance = 0
letters = 0
digits = 0

for i in str1 :
characters = characters +1
if i ==' ':
space = space + 1

if i.isalpha() == True:
letters = letters + 1

if i.isdigit() == True:
digits = digits + 1

if i =='.':
Sentance = Sentance + 1


print('Count of characters:' +" "+ str(characters))
print('Count of spaces:' +" "+ str(space))
print('Count of digits:' +" "+ str(digits))
print('Count of letters:' +" "+ str(letters))
print('Count of sentences:' +" "+ str(Sentance))
-----------------------------------------------------------------------------------------------------------------------------------------------

Add a comment
Know the answer?
Add Answer to:
Write a text analyzer program using Python. The program should prompt the user for text to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT