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
Lukas entered the date 9-17-2013 in an Excel workbook. He wants the date to appears as “Tuesday, September 17, 2013.” Instead of
Sphinxa [80]
<span>The answer is highlight cells, select the Insert tab, click on the number, select Date from the category box, highlight the correct format, and click OK.</span>
8 0
3 years ago
Providing incentives for customers to learn more about your service is known as?
Julli [10]
B) Advertising is the answer
3 0
3 years ago
Public-key cryptography (a form of asymmetric cryptography) is an encryption method that's widely used because: 1) it is computa
rosijanka [135]

Answer:

C.

Explanation:

7 0
2 years ago
Explain your understanding of distributed object system.
Paraphin [41]

Answer:

In the distributing computing, distributed object system is the process in which the distributed object are get distributed in different address space. The distributed object system is the enhancement of the client server model.

Distributed object are basically refers to the software module which are designed in such a way, so that they work together in the network.

And it is distributed physically within the network area and the methods is executed on the basis of remote host in the distributed system.  

7 0
3 years ago
You recently completed a network overhaul over the weekend. Everything seems to be functioning properly until you receive a swar
ZanzabumX [31]

Answer:

Network switch has been disconnected or switched off

Explanation:

An organization networking can be done by using several switches, routers, modems, etc. A network switch works between modem and systems, connecting the systems to the network.

A network switch is a multi-port switch that connects multiple devices to the network. mostly every floor has a network switch connected with the floor systems.

When a system is connected to switch, its indicator light on NIC is active. but as per the scenario, no system has active indicator lights on NIC, which means that there is some problem with the switch or switch is powered off.

4 0
2 years ago
Other questions:
  • What makes us see continuously moving images when still images appear in rapid succession
    11·1 answer
  • What to do when the tool bar for paint tool sai dissapears?
    12·1 answer
  • Give sally sue specific suggestions on how she can improve her powerpoint skills.
    6·1 answer
  • Which of these is the proper flow for an Auto Trans cooling system?
    7·2 answers
  • The__ key is used to group or identify a field or record within a table. (you don't need it).
    5·2 answers
  • Sam wants to move across the text and his documents to add data at predefined stops. Which key will Hughes to navigate through t
    6·1 answer
  • In Microsoft Word you can access the _______ command from the "Mini toolbar". A. insert citation B. save as C. underline D. word
    11·2 answers
  • Which of the following is considered a modern method of communication?
    7·2 answers
  • Overheating of a computer can be easily prevented. Explain how​
    15·1 answer
  • Write IF() function for student 3, If total mark is greater than 10 then print
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!