0

I have the following code which must delete a specific line in the text file notes.txt:

f = open("notes.txt","r+")

notestext = f.read()

print("NOTES:")

print(notestext)

enter = input("Press enter to add or change notes \n")

print("Type delete to delete a note or add to add a note")

start = input()
if start == "add":
    notetoadd = input("Type your note to add \n")
    f.write("\n")
    f.write(notetoadd)

Here is the problem, i dunno what to put here:

if start == "delete":
    notetodelete = input("Type the note you want to delete \n")
f.close()
Gamopo
  • 1,600
  • 1
  • 14
  • 22
Hapsti
  • 1
  • 2
  • Can you provide the text file you're using, perhaps via Pastebin or a similar service? – rustyshackleford Mar 30 '20 at 16:27
  • This post answers how to remove a line from a text file. https://stackoverflow.com/questions/4710067/using-python-for-deleting-a-specific-line-in-a-file – sokato Mar 30 '20 at 16:29

1 Answers1

0

Search for the note you want to delete using the string.index() method. You can then use string.replace() method to get your string after it gets deleted

Sai Prashanth
  • 144
  • 2
  • 11