write basic text editor allows you to add, delete, and modify lines of text Use a list of strings to store the lines, with each list element being one line.Python Programming

This task is to write a very basic text editor. It allows you to add, delete, and modify lines of text.  Use a list of strings to store the lines, with each list element being one line. The elements of the list are modified according to the commands given by the user.

 

The editor repeatedly:
1.    displays the lines entered so far prefixed with a line number in front of each and ending with an empty line.
2.    it waits for the user to enter a command
3.    if it's a valid command, it modifies the list appropriately
4.    go back to step #1

Initially, the list of lines will be empty.

You should have a function for each of the commands below, except for Quit.

The valid commands are:

 

a - add a line
Lines from the user are added to the lines collected so far. All lines entered are added to the list until the user enters a line containing a single #. 

d - delete a line
Prompt for a line number and then delete that line. Use the Python command del to delete a line from the list of lines. Check that the line number entered is valid. If it is invalid, ask for a line number again.

r - replace a line
Prompt for a line number and then replace that line with a new one from the user. Check that the line number entered is valid. If it is invalid, ask for a line number again.

f - find and replace a string
Prompt for one string (the search pattern) and then a second (the replacement). Replace all occurrences of the first string with the second, using string.replace() .

p – copy/paste lines
Prompt for two line numbers, one is the starting line of text to copy, and the second is the end line of the text to copy. Slice this part of the list, and add it to the end of the list as a single string.
Check that the line numbers entered are valid. If they are invalid, ask for a line numbers again.

c - Clear all
Delete all lines, so the state is like when the program starts.

q - Quit
End the program.

***Clarification on line numbers*** You can expect that any line numbers entered for the above functions are integers. You do NOT need to test if they are non-integer inputs, but just that they are in range of the line numbers that exist.

 

Here's an example of this editor in use. Several commands are shown. Initially, before the 'a' (add) command is used, there aren't any lines, so nothing is output before the command prompt.

Command a, d, r, f, p, c, q: a
Add a line: It is a lovely morning
Add a line: for a walk.
Add a line: It is a lovely evening
Add a line: for reading a book
Add a line: in front of the fire.
Add a line: #
1: It is a lovely morning
2: for a walk.
3: It is a lovely evening
4: for reading a book
5: in front of the fire.

Command a, d, r, f, p, c, q: d
Line number: 5
1: It is a lovely morning
2: for a walk.
3: It is a lovely evening
4: for reading a book

Command a, d, r, f, p, c, q: r
Replace line number: 2
Replacement string: for a walk in the park.
1: It is a lovely morning
2: for a walk in the park.
3: It is a lovely evening
4: for reading a book

Command a, d, r, f, p, c, q: f
Find string: lovely
Replace with: wonderful
1: It is a wonderful morning
2: for a walk in the park.
3: It is a wonderful evening
4: for reading a book

Command a, d, r, f, p, c, q: p
Start line number: 7
End line number: 8
Start line number: 1
End line number: 2
1: It is a wonderful morning
2: for a walk in the park.
3: It is a wonderful evening
4: for reading a book
5: It is a wonderful morning for a walk in the park.

Command a, d, r, f, p, c, q: c

Command a, d, r, f, p, c, q: q

For example:

 

Input

Result

a

It is a lovely morning

for a walk.

It is a lovely evening

for reading a book

in front of the fire.

#

d

5

r

2

for a walk in the park.

f

lovely

wonderful

p

7

8

1

2

c

q

Command a, d, r, f, p, c, q: a

Add a line: It is a lovely morning

Add a line: for a walk.

Add a line: It is a lovely evening

Add a line: for reading a book

Add a line: in front of the fire.

Add a line: #

1: It is a lovely morning

2: for a walk.

3: It is a lovely evening

4: for reading a book

5: in front of the fire.

 

Command a, d, r, f, p, c, q: d

Line number: 5

1: It is a lovely morning

2: for a walk.

3: It is a lovely evening

4: for reading a book

 

Command a, d, r, f, p, c, q: r

Replace line number: 2

Replacement string: for a walk in the park.

1: It is a lovely morning

2: for a walk in the park.

3: It is a lovely evening

4: for reading a book

 

Command a, d, r, f, p, c, q: f

Find string: lovely

Replace with: wonderful

1: It is a wonderful morning

2: for a walk in the park.

3: It is a wonderful evening

4: for reading a book

 

Command a, d, r, f, p, c, q: p

Start line number: 7

End line number: 8

Start line number: 1

End line number: 2

1: It is a wonderful morning

2: for a walk in the park.

3: It is a wonderful evening

4: for reading a book

5: It is a wonderful morning for a walk in the park.

 

Command a, d, r, f, p, c, q: c

 

Command a, d, r, f, p, c, q: q

Python Programming Experts

expert
Oliver
Python Programming

60 Answers

expert
Issac Torres
Python Programming

67 Answers

View More Experts
Disclaimer

The ready solutions purchased from Library are already used solutions. Please do not submit them directly as it may lead to plagiarism. Once paid, the solution file download link will be sent to your provided email. Please either use them for learning purpose or re-write them in your own language. In case if you haven't get the email, do let us know via chat support.

Get Free Quote!

264 Experts Online