There is no way to simply delete data from the middle of a file. You must read and copy the data to a new file, but leave out the lines you want to delete. Or, read all the lines into your program as a list or example, then after your program has gone through the list and deleted the entries as required, create and write the entries you decided to keep back to the file.
EDIT
Here's an example based on the code from the other answer. This has some issues but demonstrates the basic idea of what is needed.
def test():
with open('test_file', 'r') as d_file:
# Reads the entire file into a list
lines = d_file.readlines()
# We can not delete lines from the array as we try to scan through
# it with a for statement so I make a copy to work with.
copy_of_lines = lines.copy()
for line in copy_of_lines:
print(f'\n line is : {line}')
tf = input('do you want to delete this line? y/n: ')
if tf == 'y':
# The below will remove the first line that is
# the same from the list. If you have duplicate lines
# this won't always remove the correct one.
lines.remove(line) # to remove this line
print('line removed')
print(lines)
elif tf == 'n':
print(lines)
with open('test_file', 'w') as d_file: # Open in mode "w" removes all the data from the file.
d_file.writelines(lines) # Writes the entire list into the file
test()