Question: Write a PYTHON program that allows the user to navigate the lines of text in a file. The program should prompt the user for a

Write a PYTHON 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.

Hint:

To loop for line numbers from the user until she enter 0 and prints the lines number followed by the line, use the following code:

while True:

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

if len(lines) == 0:

break

lineNumber = int(input("Enter a line number [0 to quit]: "))

if lineNumber == 0:

break

elif lineNumber > len(lines):

print("ERROR: line number must be less than or equal to", len(lines))

else:

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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!