CBSE Class 12 Computer Science Question 78 of 136

Data File Handling — Question 17

Back to all questions
17
Question

Question 17

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

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