I what to make a to do list in Python, but i am having trouble with the delete commands.
This is the code:
def add():
adding = input("What do you want to add?: \n")
with open("to_do_list.txt", "a") as f:
f.write(adding + "\n")
def delete():
deleting = input("What do you want to delete?: \n")
with open("to_do_list.txt", "r+") as f:
lines = f.readlines()
for line in lines:
if line.find(deleting) == -1:
f.write(line)
def view():
with open("to_do_list.txt", "r") as f:
for line in f.readlines():
print(line)
def close():
exit()
while True:
mode = input("Add to list, delete from list, view list or leave program (add/del/view/esc) \n")
if mode == "add":
add()
elif mode == "del":
delete()
elif mode == "view":
view()
elif mode == "esc":
close()
else:
print("Mode invalid!")
continue
The delete command, nothing happens, I input what I want to delete but it does not delete it from the file. What do I have to change in the code so that it deletes the line that I want?
Please help me with these issues.