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
You were fortunate to get the ice off of the wings, but whatever caused the cabin to depressurize also vented all of your fuel o
torisob [31]

Answer:

A speed govenor

Explanation:

speed governor is an electronic device linked to the gearbox where sensors capture the movement of the vehicle. If the vehicle exceeds the specified speed limit, the device automatically slows the vehicle.

4 0
3 years ago
Microsoft's Xbox operating system provides Xbox programmers with a set of common standards to use to access controllers, the Kin
ASHA 777 [7]

not be made for Xbox platform.

Hope this helps.

3 0
3 years ago
Access to sensitive or restricted information is controlled describes which of the key communications and information systems pr
Viktor [21]

Answer:

C: Security

Explanation:

Communications and information systems principles need to be, among other things, secure. They need to be able to protect sensitive information from those who intentionally not need to know. Some incident information like voice, networks, and data, are very sensitive and thus, should be secure to the right levels and should comply with privacy laws and data protection.

4 0
3 years ago
Dropbox is an example of ________. Bluetooth technology optical storage SSD technology cloud storage
inessss [21]

IaaS

Laas is Framework as a help are online administrations that give significant level APIs used to dereference different low-level subtleties of basic organization foundation like actual registering assets, area, information dividing, scaling, security, reinforcement and so forth

7 0
2 years ago
true false the if statement causes one or more statements to execute only when a boolean expression is true
poizon [28]

Answer:

True

Explanation:

I am a coder myself and I say this is true because it executes it if the listed statement or variable is true. This is also the same for the while loop.

8 0
2 years ago
Other questions:
  • Which of the following is an example of a consumer service? computer builder motorcycle manufacturer cabinet maker air condition
    15·2 answers
  • An unwanted 'explosion' of inbox messages is called​
    8·2 answers
  • How must you rect to a flashing<br> Yellow traffic light?
    9·1 answer
  • How can you tell that a website is valid and reliable 10 points
    10·1 answer
  • If you wish to maintain a consistent style to all the documents you create, it would be helpful to use a _​
    5·1 answer
  • Which of the following is used to move to end of the row?​
    8·1 answer
  • Phil wants to make a dark themed superhero movie. What could be his target demographic
    11·2 answers
  • Describe how data is transmitted using half-duplex serial data transmission.
    9·1 answer
  • OSI layer for HDLC??​
    13·1 answer
  • I know I'm asking for a lot. But this is my last question. If we do it I pass my semester. help please.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!