Answer:
#section 1
text = input('Enter file name: ')
with open(text,'r') as file:
data = []
for line in file:
data.append(line.strip())
print('The number of lines in the file is:', len(data))
#section 2
while True:
lnum = int(input('Enter line number: '))
if lnum == 0:
break
else:
num = lnum - 1
print(data[num])
Explanation:
The programming language used is python
# section 1
In this section, the program prompts the user to enter the name of the text file, it then takes the file and opens it with a WITH statement, that allows files to be automatically closed, when they are no longer in use.
An empty list is initialized to hold the lines contained in the text file.
A FOR loop is used with an append method to scan through the file and append its contents to the empty list. The <em>.strip()</em> method is used to eliminate special characters line \t and \n, that may appear when reading the items of the file to the list.
Lastly, in this section number of lines is printed using the len() method.
#section 2
In this section, a WHILE loop is created that will continue to run untill the user inputs 0. The loop prompts the user to enter a line number and prints that number to the screen.
I have attached the result as an image.