logo Use SA10RAM to get 10%* Discount.
Order Now logo

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Himani KhatterStatistics
(/5)

745 Answers

Hire Me
expert
Varun JoharStatistics
(5/5)

967 Answers

Hire Me
expert
Justice CookResume writing
(5/5)

927 Answers

Hire Me
expert
Sujay PurakaitBusiness
(/5)

799 Answers

Hire Me
Python Programming

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.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

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

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. Develop a program to emulate a purchase transaction at a retail store. This  program will have two classes, a LineItem class and a Transaction class

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme

Get Free Quote!

392 Experts Online