KnowledgeBoat Logo

Class - 12 CBSE Computer Science Important File Handling Questions 2025

Write a program to count the number of uppercase alphabets present in a text file "Poem.txt".

Python Data Handling

1 Like

Answer

Let the file "Poem.txt" include the following sample text:

PYTHON is a Popular Programming Language.
with open("Poem.txt", 'r') as file:
    text = file.read()
    count = 0
    for char in text:
        if char.isupper():
            count += 1

print(count)
Output
9

Answered By

3 Likes