I would like to use a loop to check if the input already existed in the file regardless if it is in the list/dict. While I managed to get the input recorded in the .txt file, how do I check for repetitiveness so that I only append a new input?
f = open('History.txt', 'a+')
while True:
new_word = (input('Please enter an English word:'))
if new_word.isalpha() == True:
break
else:
print ('You''ve entered an invalid response, please try again.')
continue
f.seek(0)
f.read()
if new_word in f:
print ('The word has been recorded previously. You may proceed to the next step.')
else:
f.write(new_word + '\n')
f.close()
Currently the .txt file just keep recording the input regardless of repetitiveness.