How do I set a user input variable that will print the value of a corresponding index number?
This is the code, please help because I have been texting and emailing my professor for 2 days and and haven't received a reply.
fileName = input("Enter the name of the file, e.g. 'numbers.txt': ")
#Coutning number of lines
lineCount=0
with open(fileName, 'r') as userData:
for i in userData:
lineCount=lineCount+1
#converting index count to match linecount
blankIndex = [None]
userList = [blankIndex] + [userData]
print(lineCount)
while True:
inputTarget = int(input("Enter the number of the line you wish to see, or press enter twice to exit: "))
if inputTarget == "":
print("Enjoy your data. Goodbye!")
break
elif inputTarget == 0:
print("Great, you broke it...*slow clap*")
break
else:
print(userList[inputTarget])