Question: 1. Write a program called q1.py that analyzes and prints file statistics. First, prompt the user for the name of a file. Then, read
1. Write a program called q1.py that analyzes and prints file statistics. First, prompt the user for the name of a file. Then, read and analyze the file and display the following statistics: total number of characters, number of sentences, and number of words. Here are some notes regarding the above statistics you will collect. A character is any symbol in the text file, Examples of characters include letters, numerical digits, punctuation marks, and "invisible characters such as whitespace and newline characters. Assume a word is separated by whitespace and/or newline characters. Assume sentences end in either a period, question mark, or exclamation point. Programming tips. You'll need to take advantage of the strip() and split() func- tions for strings. Please see the Topic 3 lecture notes (along with in-class programs) for examples of reading files and stripping and splitting strings. Example #1. The user enters the filename five-letter-words.txt (line 1). The output of the program is then displayed (lines 3-5). Enter a filename: five-letter-words.txt Characters: 16500 4 Sentences: 0 Words: 2750 1 Example #2. The user enters the filename gettysburg.txt (line 1). The output of the program is then displayed (lines 3-5). Enter a filename: gettysburg.txt 3 Characters: 1447 4 Sentences: 10 Words: 267
Step by Step Solution
3.46 Rating (149 Votes )
There are 3 Steps involved in it
Heres a Python program called q1py that analyzes and prints file statistics as described ... View full answer
Get step-by-step solutions from verified subject matter experts
