I am currently creating a program that allows a user to either add or remove any word to a word list that is in a txt file however, i am having issues removing certain words that the user has requested from said text file. Here is my code(disregard the other parts):
from test_words import word_list
test_list=open('test_words.txt')
test_list=test_list.read().splitlines()
def changewords():
morewords=input('Would you like to change the word list?(Y/N)\n').upper()
if morewords=='Y':
which=input('Add, Delete, Clear or Reset?(A/D/C,R)\n').upper()
if which=='A':
add=input('What word would you like to add?\n')
file=open('test_words.txt','a')
file.write('\n')
file.write(add)
file.close()
changewords()
elif which=='D':
remove=input('what word would you like to remove?\n')
???????
file.close()
changewords()
elif which=='C':
file=open('test_words.txt','w')
file.write('')
file.close()
changewords()
elif which=='R':
file=open('test_words.txt','w')
file.write('\n'.join(word_list))
file.close()
changewords()
else:
print('Incorrect input')
changewords()
changewords()
Thanks for any help