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
What is Microsoft first product
Alenkasestr [34]

Answer:  Xenix

Explanation:

3 0
3 years ago
Read 2 more answers
5 of 10
DaniilM [7]

Answer:

what

Explanation:

3 0
2 years ago
In programming, what is a string?
Alla [95]

A way to store a sequence of letters, numbers or symbols.

This is the most accurate statement, though not entirely true.

Hope this helps.

7 0
3 years ago
Read 2 more answers
A(n) ____ is a computer that requests and uses network resources from a(n) ____.
Crazy boy [7]

A(n) client exists a computer that requests and utilizes network resources from a(n) server.

<h3>What is a computer network?</h3>
  • A computer network is a collection of computers that share resources that are available on or provided by network nodes.
  • The computers communicate with one another via digital links using standard communication protocols.
  • These links are made up of telecommunication network technologies that are based on physically wired, optical, and wireless radio-frequency means and can be configured in a variety of network topologies.
  • Nodes in a computer network can be personal computers, servers, networking equipment, or other specialized or general-purpose hosts.
  • They can be identified by network addresses and have hostnames.
  • Local-area networks (LANs) and wide-area networks (WANs) are the two basic network types.
  • A(n) client exists a computer that requests and utilizes network resources from a(n) server.

To learn more about computer network, refer to:

brainly.com/question/8118353

#SPJ4

6 0
1 year ago
What symbol following a menu command lets you know that a dialog box will be displayed? an ellipse an arrow a check mark a radio
kramer

cords   and  batteries or electric radio

5 0
2 years ago
Read 2 more answers
Other questions:
  • When creating an input control (for example, a button) on a form the _____________ indicates the data that is contained in the n
    13·1 answer
  • Does anyone know this ? this website is scratch btw.
    10·1 answer
  • How many responses does a computer expect to receive when it broadcasts an ARP request?why?
    12·1 answer
  • Machu Picchu is located in modern day _______<br><br>​
    14·2 answers
  • What is the capacity of a disk with two platters, 10,000 cylinders, an average of 400 sectors per track, and 512 bytes per secto
    9·1 answer
  • What was used to enhance silent films of the early 1900s
    15·1 answer
  • Huh? translate this please. (jk, I know what it says I just want to test everyone.)
    13·1 answer
  • 4. Write technical term for the following statements
    15·2 answers
  • Which of these allows the programmer to put data inside a variable?
    5·1 answer
  • Which of the following statements should be avoided when developing a mission statement?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!