Write a python program that will open a file and place each line of text from the file into a Python list. This program will calculate total number of lines, words and characters in the file. Write a python function counter to calculate and return total number of lines, words and characters in a text (.txt) file. The count function needs to return total number of lines, words and characters from the function. Also the function will take two parameters: • fileName is the name of the file that need to be opened to calculate the file stats (# of lines, # of words and # of characters). • lineList – this is python l

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Write a python program that will open a file and place each line of text from the file into a
Python list. This program will calculate total number of lines, words and characters in the file. Write a python function counter to calculate and return total number of lines, words and characters in a text (.txt) file. The count function needs to return total number of lines, words and characters from the function.

Also the function will take two parameters:
• fileName is the name of the file that need to be opened to calculate the file stats (# of lines, # of words and # of characters).
• lineList – this is python list that contains that will add each line (strip of new line feed in the line) to the python list.

#function count will open the file fileName and counts how many lines, words and chars
# in the file, and place each line of the file in the lineList parameter.
# The function must RETURN numOfLine, numOfWords, numOfChars as return value,
# and lineList as parameter
#
# numOfLine: number of lines in the file
# numOfWords: number of lines in the file
# numOfChars: number of lines in the file
#@parm: fileName - this is the filename to be opened
#@parm: lineList - this list contains all the text in each of lines
#              from the file. Each line of text is added to the list.
#              Need to remove the new line feed '\n' from the line
#              before adding to the list.
#@return numOfLine, numOfWords, numOfChars

def count(fileName, lineList):

After calling count function which will return 3 values and stored all the lines in the lineList parameter.
Your program needs to print out all lines stored in lineList list (MUST print out the lineList outside the count function), you MUST print out the return value of total number of lines, words, and characters. These values are returned from count function.

In addition, you need to print out number of uppercase letters, lowercase letters, spaces, digits, sentences. Assuming each sentences ends with a period ’.’, exclamation mark (!) or questions mark ‘?’.
All the printout MUST be outside the count function. That is, you can NOT print them within the count function.

An example text file has been given along with the end result when used with the python program. The program created should have an out put that matches the example given.

 
1: Python is an interpreted, high-level, general-purpose
Line 2 : programming language. Created by Guido van Rossum and
Line 3 : first released in 1991, Python's design philosophy
Line 4 : emphasizes code readability with its notable use of
Line 5 : significant whitespace. Its language constructs and
Line 6 : object-oriented approach aim to help programmers
Line 7 : write clear, logical code for small and large-scale
Line 8 : projects.
Line 9 :
Line 10 : Python is meant to be an easily readable language.
11 : Its formatting is visually uncluttered, and it often
Line 12 : uses English keywords where other languages use
Line 13 : punctuation. Unlike many other languages, it does
Line 14 : not use curly brackets to delimit blocks, and
Line 15 : semicolons after statements are optional.
Total number of lines: 15
Total number of words: 94
Total number of characters: 662
Total number of uppercase letters: 10
Total number of lowercase letters: 538
Total number of spaces: 92
Total number of digits: 4
Total number of sentences:
6
Transcribed Image Text:1: Python is an interpreted, high-level, general-purpose Line 2 : programming language. Created by Guido van Rossum and Line 3 : first released in 1991, Python's design philosophy Line 4 : emphasizes code readability with its notable use of Line 5 : significant whitespace. Its language constructs and Line 6 : object-oriented approach aim to help programmers Line 7 : write clear, logical code for small and large-scale Line 8 : projects. Line 9 : Line 10 : Python is meant to be an easily readable language. 11 : Its formatting is visually uncluttered, and it often Line 12 : uses English keywords where other languages use Line 13 : punctuation. Unlike many other languages, it does Line 14 : not use curly brackets to delimit blocks, and Line 15 : semicolons after statements are optional. Total number of lines: 15 Total number of words: 94 Total number of characters: 662 Total number of uppercase letters: 10 Total number of lowercase letters: 538 Total number of spaces: 92 Total number of digits: 4 Total number of sentences: 6
Python is an interpreted, high-level, general-purpose
programming language. Created by Guido van Rossum and
first released in 1991, Python's design philosophy
emphasizes code readability with its notable use of
significant whitespace. Its language constructs and
object-oriented approach aim to help programmers
write clear, logical code for small and large-scale
projects.
Python is meant to be an easily readable language.
Its formatting is visually uncluttered, and it often
uses English keywords where other languages use
punctuation. Unlike many other languages, it does
not use curly brackets to delimit blocks, and
semicolons after statements are optional.
Transcribed Image Text:Python is an interpreted, high-level, general-purpose programming language. Created by Guido van Rossum and first released in 1991, Python's design philosophy emphasizes code readability with its notable use of significant whitespace. Its language constructs and object-oriented approach aim to help programmers write clear, logical code for small and large-scale projects. Python is meant to be an easily readable language. Its formatting is visually uncluttered, and it often uses English keywords where other languages use punctuation. Unlike many other languages, it does not use curly brackets to delimit blocks, and semicolons after statements are optional.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY