CBSE Class 12 Computer Science Question 126 of 145

File Handling — Question 6

Back to all questions
6
Question

Question 6

Write a program to count the number of upper-case alphabets present in a text file "Article.txt".

Answer

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

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

print(count)
Output
9