该题目为第一章第八题。
# 要求输入文件名
fileName = input("Enter file name:")
#打开文件
inputFile = open(fileName, 'r')
lines = list()
for line in inputFile:
lines.append(line)
while True:
print("The file has", len(lines), "lines.")
if len(lines) == 0:
break
lineNumber = int(input("Enter a line number: "))
if lineNumber == 0:
break
elif lineNumber >= len(lines):
print("ERROR")
else:
print(lineNumber, ": ", lines[lineNumber])