Ok so im going to list my question and then the work so far. Here is the code so far:(THE PROBLEM WITH THE CODE IS THAT THE IM SUPPOSE TO USE FIND() TO REPEATEDLY CHANGE THE OCCURRENCE OF THE WORD "MASK" TO THE WORD "HAT" IN THE FILE BUT AM KIND OF LOST HAVE BEEN WORKING ON THIS FOR A WEEK AND A HALF) ALSO I CAN NOT use the replace method, count method, split method, range() function, or lists in your solution. HAVE BEEN TRYING TO FIND SUM WAY TO USE FIND() BUT AM COMING UP SHORT here's the code i have so far: inputfile = input('Enter input file name: ') outputfile = input('Enter output file name: ') input_data = open(inputfile, 'r') # this opens the file to read it. output_data = open(outputfile, 'w') # this opens a file to write to. userStr = (input('Enter target string:')) # this prompts the user for a word userReplace = input('Enter replacement string: ') # this prompts the user for the replacement word for line in input_data: if userStr in line: output_data.write(userReplace.join(line.split(userStr))) input_data.close() # this closes the documents we opened before output_data.close() This works but i CAN NOT use the replace method, count method, split method, range() function, or lists in your solution and i realized that i have .split in my code. I was told to use find() to get all occurrences and I'm having trouble USING FIND() to get all occurrences if i can incorporate the FIND() i will be good I'm just having trouble getting it.
Ok so im going to list my question and then the work so far.
Here is the code so far:(THE PROBLEM WITH THE CODE IS THAT THE IM SUPPOSE TO USE FIND() TO REPEATEDLY CHANGE THE OCCURRENCE OF THE WORD "MASK" TO THE WORD "HAT" IN THE FILE BUT AM KIND OF LOST HAVE BEEN WORKING ON THIS FOR A WEEK AND A HALF) ALSO I CAN NOT use the replace method, count method, split method, range() function, or lists in your solution. HAVE BEEN TRYING TO FIND SUM WAY TO USE FIND() BUT AM COMING UP SHORT
here's the code i have so far:
inputfile = input('Enter input file name: ')
outputfile = input('Enter output file name: ')
input_data = open(inputfile, 'r') # this opens the file to read it.
output_data = open(outputfile, 'w') # this opens a file to write to.
userStr = (input('Enter target string:')) # this prompts the user for a word
userReplace = input('Enter replacement string: ') # this prompts the user for the replacement word
for line in input_data:
if userStr in line:
output_data.write(userReplace.join(line.split(userStr)))
input_data.close() # this closes the documents we opened before
output_data.close()
This works but i CAN NOT use the replace method, count method, split method, range() function, or lists in your solution and i realized that i have .split in my code. I was told to use find() to get all occurrences and I'm having trouble USING FIND() to get all occurrences if i can incorporate the FIND() i will be good I'm just having trouble getting it.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 3 images