KnowledgeBoat Logo

Class - 12 CBSE Computer Science Important File Handling Questions 2025

Write a program to accept string/sentences from the user till the user enters “END” to. Save the data in a text file and then display only those sentences which begin with an uppercase alphabet.

Python File Handling

1 Like

Answer

f = open("new.txt", "w")
while True:
    st = input("Enter next line:")
    if st == "END":
        break
    f.write(st + '\n')
f.close()

f = open("new.txt", "r")
while True:
    st = f.readline()
    if not st:
        break
    if st[0].isupper():
        print(st)
f.close()
Output
Enter next line:Hello world
Enter next line:welcome to     
Enter next line:Python programming
Enter next line:END
Hello world

Python programming

Answered By

3 Likes