Computer Science, asked by anirud123, 6 months ago

Write a function remove_lowercase() that accepts two filenames, and copies all he lines

that do not start with a lowercase letter from the first file into the second.​

Answers

Answered by mohitx618
20

Answer:

def remove_lowercase(x,y):

m=open(x)

n=open(y,"w")

k=m.readlines()

for i in k:

if i[0].isupper():

n.write(i)

n.write(" ")

#main

a=input("enter file name to read")

b=input("enter file name to write")

c=remove_lowercase(a,b)

Answered by surajnegi0600
0

Answer:

A function in Python that implements the described behavior:

def remove_lowercase(filename1, filename2):

   with open(filename1, 'r') as file1:

       with open(filename2, 'w') as file2:

           for line in file1:

               if not line[0].islower():

                   file2.write(line)

Explanation:

The given function takes in two file names, filename1 and filename2, as parameters. It opens the first file in read mode and the second file in write mode using Python's with the statement. The with statement ensures that the file is properly closed after the indented block of code is executed. The function then iterates over each line in the first file and checks if the first character of the line is not in lowercase using the islower() method. If the first character is not in lowercase, the line is written to the second file using the write() method. The end result of this function is a new file, filename2, that only contains lines from filename1 that start with a character that is not in lowercase.

More questions and answers

https://brainly.in/question/16964478?referrer=searchResults

https://brainly.in/question/7429916?referrer=searchResults

#SPJ3

Similar questions