Question: Python: Write a class Editor that allows a user to perform the commands shown below using a menu. The class should have an instance variable
Python:
Write a class Editor that allows a user to perform the commands shown below using a menu. The class should have an instance variable called text lines containing a list of strings (corresponding to the list of text lines being edited). Implement the menu in such a way that clear names (as opposed to, say, numbers) are used to identify each command to the user. Also, make sure each command (except quit, which is trivial) is implemented by a method with the commands name which takes as argument the string read from input (after taking the command part off the string). For example, command print num will be implemented by print num(self,rest string) and delete num will be implemented by delete num(self,rest string). print num: which prints the line of text at position num, and if no num is given prints all the lines. Note that what the user refers to as line 1 is what text lines stores in position 0. Thus, you need to convert the numbers given by the user to the indices used by your array.
delete num: which deletes the line of text at position num, and deletes all the lines if no num is given. Same issue as above for nums.
insert num: which inserts immediately from position num onwards, any line of text subsequently written by the user in the order entered, until the user types a full stop on a line by itself. Note that full stops that are not on a line by themselves should not terminate the input. Do not store the full stop in the list. For example, if the user types insert 3 and then types lines Hello I am well. How are you? . then string "Hello" will be added to text lines at position 2 (remember it starts at 0, so Hello becomes the third line in the list), and string "I am well. How are you?" will be added at position 3, with all items in the text lines that used to appear from 2 onwards, now appearing from 4 onwards.
quit: which quits the program.
Test each of the functionality provided by the menu, that is, test the functions that implement the menu (like print num(self,string)). Important: All errors should be caught and a question mark, ?, should be printed when an error occurs, so that the user is given the opportunity to provide correct input data. Negative number lines are possible and should be handled following the convention described for the original list implementation. For example, num = -1 refers to the last line of the text
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
