Class - 12 CBSE Computer Science Important File Handling Questions 2025
Write a function Remove_Lowercase() that accepts two file names, and copies all lines that do not start with lowercase letter from the first file into the second file.
Python Data Handling
2 Likes
Answer
Let the file "file1.txt" include the following sample text:
Dew on petals, morning's gift.
silent moon, silver glow.
Winds whisper, secrets shared.
rain's embrace, earth's renewal.
def Remove_Lowercase(input_file, output_file):
input_file = open(input_file, 'r')
output_file = open(output_file, 'w')
for line in input_file:
if line.strip() and line[0].isupper():
output_file.write(line)
input_file.close()
output_file.close()
input_file = 'file1.txt'
output_file = 'file2.txt'
Remove_Lowercase(input_file, output_file)
The file "file2.txt" includes following text:
Dew on petals, morning's gift.
Winds whisper, secrets shared.
Answered By
3 Likes