LearnPy Hub
← File Handling problems
Medium

Find and Replace in a File

Read n lines and write them to story.txt. Read an old word and a new word. Write a copy of the file to story_new.txt with every occurrence replaced, then print the new file and how many replacements were made.

Input

n; n lines; old word; new word.

Output

Lines.

Sample 1

Input
2
the cat sat
the cat ran
cat
dog
Output
the dog sat
the dog ran
2

Sample 2

Input
1
hello
x
y
Output
hello
0
solution.py
Output appears here
Find and Replace in a File · Python practice problem · LearnPy Hub