My code:
fname = "text.txt"
text_file = open(fname, "r")
lines = text_file.readlines()
while True:
linenumber = int(input("Please enter a line number or press 0 to quit: "))
if linenumber == 0:
print("Thanks for using the program")
break
text_file.close()
How can I add an exception(try/except) handling, so that after entering, for example, the number of line 30 which does not exist, an exception appears, eg "This line does not exist", I have a big problem with it, could someone help?
Thanks in advance!!!