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
LiRa
2 months 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:
amid [951]2 months ago
7 0

This code is in Python. I'm not certain what programming language you need.

Refer to the image:

Harlamova29_29 [1K]2 months ago
7 0

Answer:

#section 1

filename = input('Enter file name: ')

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

   

   lines = []

   for line in file:

         lines.append(line.strip())

print('Total lines in the file:', len(lines))

#section 2

while True:

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

   if line_number == 0:

       break

   else:

       index = line_number - 1

       print(lines[index])

Explanation:

The programming language utilized is Python

# section 1

In this part, the program prompts the user for the file's name. It opens the file using a WITH statement, ensuring that it closes automatically when done.

An empty list is created to store the lines from the file.

A FOR loop is implemented to read through the file, adding each line to the list. The .strip() function removes any unwanted characters such as \t and \n from the text.

At the end of this section, the total line count is displayed using the len() function.

#section 2

<pIn this section, a WHILE loop is initiated to continue running until the user enters 0. The loop requests a line number from the user and then outputs that line's content to the screen.

I have included the result as an image.

You might be interested in
Which of the following best describes how computing devices represent information? A. A computer will either represent informati
oksian1 [950]

Answer:

The answer is B.

Explanation:

The justification for choosing B is that "bytes" represent the correct method for storing data in binary form of 0s and 1s.

5 0
2 months ago
Read 2 more answers
Which of the following best describes the protocols used on the Internet?
amid [951]
Typical Internet protocols encompass TCP/IP (Transmission Control Protocol/Internet Protocol), UDP/IP (User Datagram Protocol/Internet Protocol), HTTP (HyperText Transfer Protocol), and FTP (File Transfer Protocol).
8 0
2 months ago
Which two statements are true regarding the user exec mode? (choose two.)?
Natasha_Volkova [1026]
<span>To enter global configuration mode, you need to type the enable command.</span><span>
The prompt indicating this mode concludes with the ">" symbol.</span>
8 0
1 month ago
Other questions:
  • Write a program that takes a date as input and outputs the date's season. The input is a string to represent the month and an in
    13·2 answers
  • The part of the computer that contains the brain, or central processing unit, is also known as the A.monitor B.modem C.keyboard
    10·1 answer
  • 3. Megan and her brother Marco have a side business where they shop at flea markets, garage sales, and estate
    9·1 answer
  • Write a method printShampooInstructions(), with int parameter numCycles, and void return type. If numCycles is less than 1, prin
    14·1 answer
  • 7.7 LAB: Using a while loop countdown Write a program that takes in an integer in the range 10 to 100 as input. Your program sho
    11·1 answer
  • Language levels have a direct influence on _______________
    10·1 answer
  • Suggest two other subtasks that may be performed in a dice game?
    15·2 answers
  • When using the following symbol, there are two arrows coming out of it. One arrow corresponds to what happens in the program if
    7·1 answer
  • While creating an animation, Gina has prepared a document stating the purpose and type of audience for the animation. What has
    6·1 answer
  • The matrix theory is used in the ___ technique
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!