1answer.
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]
3 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]3 years ago
7 0

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

See picture:

mrs_skeptik [129]3 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
________ programs help solve the problem of running out of storage space by providing lists of application programs, stored vide
Leviafan [203]

Answer:

Storage management

Explanation:

The programs that do this are known as Storage management programs. They are incredibly useful since they allow you to see which files are taking up the most amount of space as well as the importance that each file has on the system. Many of these programs have a different visual representation of the files such as pie charts or system blocks showing the percentage of space it is taking up. Everything in these programs is made to help the end-user visualize and analyze their data thoroughly.

7 0
3 years ago
The function of a start winding in a split-phase motor is to A. provide the starting torque. B. reduce the starting current. C.
gulaghasi [49]
The most appropriate answer is A, the the start winding on a split-phase motor is to provide a starting torque. A split-phase motor is a single phase electrical motor (common in many household applications such as washing machines and household fans), with two distinct windings on the stator coils, the start windings and the run windings, at 90 degrees apart. When the motor is energised the start coils acts like a second phase (2 phase motor) and helps provide the rotating magnetic field that is necessary to turn the rotor. Once moving, only the run winding (single phase) is required to keep the motor spinning.

The other answers are irrelevant for the starting of the motor.
4 0
3 years ago
Implement a function inValues() that asks the user to input a set of nonzero floating-point values. When the user enters a value
elena-s [515]

Answer:

Explanation:

The following is written in Python and uses exception handling to do exactly as requested. It then goes adding all of the integer values to an array called num_list and finally adding them all together when the function ends.

def in_values():

   num_list = []

   while True:

       try:

           num = input("Input non-zero floating point: ")

           num = int(num)

           if num == 0:

               break

           else:

               num_list.append(num)

       except ValueError:

           print("No valid integer! Please try again ...")

           try:

               num = input("Input non-zero floating point: ")

               num = int(num)

               break

           except ValueError:

               break

   sum = 0

   for number in num_list:

       sum += number

   return sum

5 0
3 years ago
En que parte del mall del rio venden tarjetas de google play en cuenca​
JulijaS [17]

chxgfk hcyskvuct auhchovuzq vuvscisv

6 0
3 years ago
Sites like Zillow get input about house prices from a database and provide nice summaries for readers. Write a program with two
Alexeev081 [22]

Answer:

In Python:

cprice= int(input("Current price: "))

lmonth= int(input("Last month's price: "))

print("This house is $"+str(cprice))

print("The change is $"+str(cprice-lmonth)+" since last month")

print("The current mortage $"+str((cprice * 0.051) / 12)+" since last month")

Explanation:

Get current price

cprice= int(input("Current price: "))

Get last month's price

lmonth= int(input("Last month's price: "))

Print the current price

print("This house is $"+str(cprice))

Print the change

print("The change is $"+str(cprice-lmonth)+" since last month")

Print the mortgage

print("The current mortage $"+str((cprice * 0.051) / 12)+" since last month")

8 0
3 years ago
Other questions:
  • Consider a set of mobile computing clients in a certain town who each
    13·1 answer
  • Which of the following parameters should match in order for a pair of routers to form an adjacency when running OSPFv2? (Points
    9·1 answer
  • If an app needs to perform a derived-class-specific operation on a derived class object reference by a base class variable, the
    9·1 answer
  • When you purchase an item in a store, you may be charged __________.
    11·2 answers
  • Which group on the home ribbon contains commands to control the alignment of text in a document?
    15·1 answer
  • Define<br>output<br>devices<br>.<br>Give<br>any<br>three<br>examples<br>.<br>3.​
    8·2 answers
  • Give two examples of html structure
    15·1 answer
  • Kelly has always used "P4ssw0rd” as her password on her online accounts. Why should she change this? Check all that apply.
    8·2 answers
  • Can you see the processing step yes or no
    8·2 answers
  • I cant tell if tubbo is a bee or a goat <br>or could he be human in the smp
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!