I have to write a program that takes a word from the user and replaces it if it is in the text file with another word given by the user. Then takes that input and writes it to a new file. The only problem is, I have to do it without using the built in replace() string function.
What I have so far:
input_data = open('input.txt','r') output_data = open('output.txt','w') x = input('Enter the word to be replaced:') y = input('What should I replace all occururrences of ', x, 'with?') for line in input_data.split(): for word in line: if word in line: #Not sure what is supposed to go here without replace. output_data.write(line) input_data.close() output_data.close()
Any hints or suggestions would be immensly helpful.