subject

This is in Python! 8.28 Develop a class Textfile that provides methods to analyze a text file. The class
Textfile will support a constructor that takes as input a file name (as a string) and instantiates
a Textfile object associated with the corresponding text file. The Textfile class should support methods nchars(), nwords(), and nlines() that return the number
of characters, words, and lines, respectively, in the associated text file. The class should
also support methods read() and readlines() that return the content of the text file as a
string or as a list of lines, respectively, just as we would expect for file objects.
Finally, the class should support method grep() that takes a target string as input and
searches for lines in the text file that contain the target string. The method returns the lines
in the file containing the target string; in addition, the method should print the line number,
where line numbering starts with 0.
>>> t = Textfile('raven. txt') File: raven. txt
>>> t. nchars()
6299
>>> t. nwords()
1125
>>> t. nlines()
126
>>> print(t. read())
Once upon a midnight dreary, while I pondered weak and weary,
...
Shall be lifted - nevermore!
>>> t. grep('nevermore')
75: Of `Never-nevermore.`
89: She shall press, ah, nevermore!
124: Shall be lifted - nevermore!

8.29 Add method words() to class Textfile from Problem 8.28. It takes no input and
returns a list, without duplicates, of words in the file.

8.30 Add method occurrences() to class Textfile from Problem 8.28. It takes no input
and returns a dictionary mapping each word in the file (the key) to the number of times it
occurs in the file (the value).

8.31 Add method average() to class Textfile from Problem 8.28. It takes no input and
returns, in a tuple object, (1) the average number of words per sentence in the file, (2) the
number of words in the sentence with the most words, and (3) the number of words in the
sentence with the fewest words. You may assume that the symbols delimiting a sentence
are in '!?.'.

8.41 Consider the class tree hierarchy:
Animal
Mammal
Cat Dog Primate
Hacker
Implement six classes to model this taxonomy with Python inheritance. In class Animal,
implement method speak() that will be inherited by the descendant classes of Animal as
is. Complete the implementation of the six classes so they exhibit this behavior:
>>> garfield = Cat()
>>> garfield. speak()
Meeow
>>> dude = Hacker()
>>> dude. speak( )
Hello world!

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 03:00
Data is processed, stored, and transmitted as a series of 1s and 0s. each 1 or 0 is called a(n) . a series of eight 0s and 1s, called a(n) , represents one character—a letter, number, or punctuation mark. data becomes when it is presented in a format that people can understand and use. digital signals are represented by two different , such as +5 volts and +.2 volts. digital data can also take the form of light and dark spots etched onto the surface of a cd or the positive and negative orientation of particles on the surface of a hard disk. data consists of numbers that might be used in arithmetic operations. it can be represented digitally using the number system. data is composed of letters, symbols, and numerals that are not used in arithmetic operations. computers represent this type of data using , ebcdic, unicode, or utf-8. data is quantified using terms such as or kibibyte (1024 bytes), and prefixes such as or mebi (1,048,576), and giga or (1,073,741,824). to reduce file size and transmission times, digital data can be compressed. compression provides the means to compress data and reconstitute it into its original state. compression throws away some of the original data during the compression process. compressed files usually have at the end of the file name and are represented with special icons. these files have to be or unzipped before you can view the data they contain.
Answers: 1
question
Computers and Technology, 23.06.2019 00:10
My has been slow anyone else’s ?
Answers: 1
question
Computers and Technology, 23.06.2019 07:00
To produce a starlight effect in her photograph, lina should choose the filter for her camera.
Answers: 1
question
Computers and Technology, 23.06.2019 17:00
1. which of the following is not an example of an objective question? a. multiple choice. b. essay. c. true/false. d. matching 2. why is it important to recognize the key word in the essay question? a. it will provide the answer to the essay. b. it will show you a friend's answer. c. it will provide you time to look for the answer. d. it will guide you on which kind of answer is required.
Answers: 1
You know the right answer?
This is in Python! 8.28 Develop a class Textfile that provides methods to analyze a text file. The...
Questions
question
Arts, 28.01.2021 16:30
question
Mathematics, 28.01.2021 16:30
question
History, 28.01.2021 16:30
question
Mathematics, 28.01.2021 16:30
question
Mathematics, 28.01.2021 16:30
Questions on the website: 13722361