Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
269 views
in Computer by (75 points)
Write the definition of a function Change Gender() in Python, which reads the contents of a text file "BIOPIC. TXT" and displays the content of the file with every occurrence of the word 'he replaced by 'she. For example, if the content of the file "BIOPIC. TXT" is as follows: Last time he went to Agra, there was too much crowd, which he did not like. So this time he decided to visit some hill station. The function should read the file content and display the output as follows: Last time she went to Agra, there was too much crowd, which she did not like. So this time she decided to visit some hill station.

Please log in or register to answer this question.

1 Answer

+1 vote
by (32.0k points)

Here's the Python code for the ChangeGender() function that reads the contents of a text file "BIOPIC.TXT" and replaces every occurrence of the word 'he' with 'she':

def ChangeGender():
    # Open the file in read mode
    with open("BIOPIC.TXT", "r") as file:
        # Read the contents of the file
        content = file.read()
        
        # Replace 'he' with 'she' in the content
        updated_content = content.replace("he", "she")
        
        # Print the updated content
        print(updated_content)

# Call the function
ChangeGender()

Make sure to place this code in the same directory where the "BIOPIC.TXT" file is located. When you run this code, it will read the contents of the file "BIOPIC.TXT", replace every occurrence of 'he' with 'she', and then display the updated content.

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...