In pthon,  how can I fix this code so that it changes the word 'language' in the file to test below where the user inputs info? ile=input('Enter a file name : ') string1=input('Enter a string to be replaced : ') string2=input('Enter a string to be added : ') with open(file,'r') as f:     data=f.read() data=data.replace(string1,string2) with open(file,'w') as f:     f.write(data) f = open(file, "r") print(f.read())     the file is called Problem 2.txt and contains the following text:   Python language is incredibly easy to use and learn for new beginners and newcomers. The python language is one of the most accessible programming languages available because it has simplified syntax and not complicated, which gives more emphasis on natural language. Due to its ease of learning and usage, python codes can be easily written and executed much faster than other programming languages. right now, the text just displays:   Enter a file name : problem 2.txt Enter a string to be replaced : language Enter a string to be added : test   however, I need  the output to look like this: Enter a file name : problem 2.txt Enter a string to be replaced : language Enter a string to be added : test Python test is incredibly easy to use and learn for new beginners and newcomers. The python test is one of the most accessible programming tests available because it has simplified syntax and not complicated, which gives more emphasis on natural test. Due to its ease of learning and usage, python codes can be easily written and executed much faster than other programming tests.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

In pthon, 

how can I fix this code so that it changes the word 'language' in the file to test below where the user inputs info?

ile=input('Enter a file name : ')
string1=input('Enter a string to be replaced : ')
string2=input('Enter a string to be added : ')
with open(file,'r') as f:
    data=f.read()
data=data.replace(string1,string2)
with open(file,'w') as f:
    f.write(data)
f = open(file, "r")
print(f.read())    

the file is called Problem 2.txt and contains the following text:

 

Python language is incredibly easy to use and learn
for new beginners and newcomers. The python language
is one of the most accessible programming languages
available because it has simplified syntax and not
complicated, which gives more emphasis on natural
language. Due to its ease of learning and usage,
python codes can be easily written and executed much
faster than other programming languages.

right now, the text just displays:

 

Enter a file name : problem 2.txt
Enter a string to be replaced : language
Enter a string to be added : test

 

however, I need  the output to look like this:

Enter a file name : problem 2.txt
Enter a string to be replaced : language
Enter a string to be added : test

Python test is incredibly easy to use and learn
for new beginners and newcomers. The python test
is one of the most accessible programming tests
available because it has simplified syntax and not
complicated, which gives more emphasis on natural
test. Due to its ease of learning and usage,
python codes can be easily written and executed much
faster than other programming tests.

 

Expert Solution
steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY