answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
notsponge [240]
2 years ago
6

Write a program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename

and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the program quits. Otherwise, the program prints the line associated with that number

Computers and Technology
2 answers:
Basile [38]2 years ago
7 0

This is written in Python. Not sure what computer language you need.

See picture:

mrs_skeptik [129]2 years ago
7 0

Answer:

#section 1

text = input('Enter file name: ')

with open(text,'r') as file:

   

   data = []

   for line in file:

         data.append(line.strip())

print('The number of lines in the file is:', len(data))

#section 2

while True:

   lnum = int(input('Enter line number: '))

   if lnum == 0:

       break

   else:

       num = lnum - 1

       print(data[num])

Explanation:

The programming language used is python

# section 1

In this section, the program prompts the user to enter the name of the text file, it then takes the file and opens it with a WITH statement, that allows files to be automatically closed, when they are no longer in use.

An empty list is initialized to hold the lines contained in the text file.

A FOR loop is used with an append method to scan through the file and append its contents to the empty list. The <em>.strip()</em> method is used to eliminate special characters line \t and \n, that may appear when reading the items of the file  to the list.

Lastly, in this section number of lines is printed using the len() method.

#section 2

In this section, a WHILE loop is created that will continue to run untill the user inputs 0. The loop prompts the user to enter a line number and prints that number to the screen.

I have attached the result as an image.

You might be interested in
Which is a connectionless protocol in the transport layer? What are the small chunks of data called?
xeze [42]

Answer:

User Datagram Protocol (UDP) , transport-layer segment.

Explanation:

The User Datagram Protocol is popularly known as UDP. It is defined as the communication protocol which is used across the internet for any time sensitive transmission like the DNS lookup or the video playback.

The UDP provides a unreliable and connectionless service to a invoking application.

The transport layers on sending side converts the application $\text{layer }$ messages which it $\text{receives}$ from the $\text{sending application process}$ into a transport layer segment called as the transport layer segments. This is achieved by breaking down the application messages into a smaller chunks and then adding the transport layer header into each chunk so as to create a transport layer segment.

6 0
2 years ago
Read 2 more answers
Consider the following method intended to modify the parameter names by removing all instances of the String n.
Anastasy [175]

Answer:

int i = 0; i < names.size(); i++

Explanation:

The ArrayList must be read in the forward direction, and it is going to start from 0 certainly. Also, the iteration is going to end when i is exactly one less than the size of the ArrayList. And this is possible only if we choose the option mentioned in the Answer section. In this, i starts from 0 and iterates till i is one less than name.size() which is the size of the ArrayList.

7 0
2 years ago
f the copyright date on the homepage is more than 1 year old, the website should always be considered unmaintained
Lilit [14]
We still have moderators who watch the site every day they are in the process of acquiring a new one 
4 0
2 years ago
The ________ program displays graphics and loading screens during the boot process.
Minchanka [31]
Booting would be complete if the normal, runtime environment has been achieved. A boot loader is a program that loads operating system for the computer after the completion of power on tests. The boot manager is a program that displays graphics and loading screens during the boot process.
3 0
2 years ago
Enter a formula in cell G5 that calculates the difference between the attendance totals for 2018 and 2017. Copy the formula to t
Allushta [10]
This is done by a very simple formula: the only thing you need to type is =x-y where x is the cell that contains the total of 2018 and y being the cell that contains the total for 2017. If both are numeric values you can use the formula = A1-B1 and get your result. Your <span>cells don't have to be in the same order as your formula.</span>
4 0
2 years ago
Other questions:
  • Where is the Name Manager dialog box found?
    13·1 answer
  • Compare the encryption algorithms found in s-tools: idea, mdc, des, and 3des.
    5·1 answer
  • The video clip on driverless cars explained that brain signals from the individual wearing the headset are converted by computer
    13·2 answers
  • Joe runs a handyman service. He enjoys writing and keeping up on the latest trends. He wants to share this information with his
    7·1 answer
  • What is the other name designated to a game master of multiplayer online games (MMOs)?
    11·2 answers
  • In a graphical user interface, which is a small symbol on the screen whose location and shape changes as a user moves a pointing
    10·1 answer
  • Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation
    6·1 answer
  • Your network administrator finds a virus has been successfully inserted into the network software. The virus itself is now consi
    10·2 answers
  • Information in​ folders, messages,​ memos, proposals,​ emails, graphics, electronic slide​ presentations, and even videos create
    7·1 answer
  • When should a developer begin thinking about scalability? 1 during the design phase 2during testing 3when traffic increases by 2
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!