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
ArbitrLikvidat [17]
3 years ago
7

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.
It should be like as this sample run follows.

Enter the input file name: quotes.xtxt
I cannot open the file quotes.xtxt - Please check the name and try again.
Enter the input file name: quotes.txt
The file has 16 lines.
Enter a line number [0 to quit]: 1
1: Hakuna Matata!
Enter a line number [0 to quit]: -1
Try again. Line number must be between 0 and 16
Enter a line number [0 to quit]: 16
16: Just keep swimming!
Enter a line number [0 to quit]: 17
Try again. Line number must be between 0 and 16
Enter a line number [0 to quit]: 5
5: It's kind of fun to do the impossible.
Enter a line number [0 to quit]: A
Try again. Please enter a number between 0 and 16
Enter a line number [0 to quit]: $
Try again. Please enter a number between 0 and 16
Enter a line number [0 to quit]: 4
4: To infinity and beyond!
Enter a line number [0 to quit]: 0
Computers and Technology
1 answer:
pickupchik [31]3 years ago
7 0

Answer:

Explanation:

iname=input("Enter the file name: ")

inputfile=open(iname,'r')

lines=[]

for line in inputfile:

lines.append(line)

inputfile.close()

print("The file has ",len(lines)," lines")

while True:

linenumber=int(input("Enter the line number or 0 to quit: "))

if linenumber==0:

break

elif linenumber > len(lines):

print("Error: line number must be less than ", len(lines))

else:

print(linenumber, " : ", lines[linenumber - 1])

You might be interested in
In the ____________________ approach, the project is initiated by upper-level managers who issue policy, procedures and processe
FrozenT [24]

Answer:

top-Down

Explanation:

4 0
3 years ago
You have found an old dusty computer in your basement that you can identify as an original IBM PC. You ask your friend if he kno
fredd [130]

Answer:

Pentium

Explanation:

8 0
3 years ago
Ideally, how often should you back up the data on your computer? once an hour, once a day, once a month, once a year. Please hur
Stells [14]

Explanation:

Every month or so

5 0
3 years ago
Read 2 more answers
Find each of the following products using distributive property a) 735 × 16​
Alekssandra [29.7K]

Answer:

735 * 16 = 11760

Explanation:

Given

735 * 16

Required

The product using distributive property

Express 16 as 10 + 6

735 * 16 = 735 * (10 + 6)

Distributive property states that:

a * (b + c) = a * b + a * c

So, the expression becomes

735 * 16 = 735 * 10 + 735 *6

Evaluate each product

735 * 16 = 7350 + 4410

735 * 16 = 11760

8 0
3 years ago
A resistor bank is connected to a controller with conductor insulation rated 75 °C. The resistors are not used in conjunction wi
irina [24]

Explanation:

This means that it requires a disconnecting means for each motor, and it must be located in sight from the motor location and the driven machinery location.

Multiply the FLC of the largest motor by 125%.

Add up the FLCs of the other motors.

Multiply the continuous non-motor loads by 125%.

Add up all of the above to the total of the non-continuous loads.

3 0
3 years ago
Other questions:
  • Given positive integer numInsects, write a while loop that prints that number doubled without reaching 200. Follow each number w
    8·1 answer
  • Fill in the blanks:(a)Every Java program must have at least one ______________.(b)The Java program is executed from _________ me
    12·1 answer
  • Sarah is working on a project in which she needs to record all the extracurricular activities in her college. Her college teache
    5·1 answer
  • 2
    11·1 answer
  • What would be the best engine to use for making a 3d beginner game
    9·1 answer
  • Llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll
    7·1 answer
  • You are splitting up all your apples equally between 3 people. which statement below will calculate how many apples will be left
    12·1 answer
  • Can somebody PLEASE help me cancel my subscription I have tried so many different things and contacted support - they are no hel
    14·1 answer
  • Plsssssssss help me​
    8·1 answer
  • Between the div tags below, type the code for a link to the second.html page. Use "Go to the Second Page" as the link text
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!