Part of the series

Several example codes

~1 min read • Updated Sep 24, 2025

Program Overview

This Python program reads a string and counts the number of uppercase and lowercase letters.
It stores the results in a dictionary with two keys: "UPPER-CASE" and "LOWER-CASE".
This approach is useful for text analysis, formatting checks, and case-sensitive validation.


Python Code:


# Read input string from user
text = input("Enter a string: ")

# Initialize dictionary to store counts
case_count = {"UPPER-CASE": 0, "LOWER-CASE": 0}

# Count uppercase and lowercase letters
for ch in text:
    if ch.isupper():
        case_count["UPPER-CASE"] += 1
    elif ch.islower():
        case_count["LOWER-CASE"] += 1

# Display the result
print("Case analysis:", case_count)

Sample Output:


Enter a string: Hello World!  
Case analysis: {'UPPER-CASE': 2, 'LOWER-CASE': 8}

Explanation:

- The user inputs a string
- A dictionary case_count is initialized with keys for uppercase and lowercase
- Each character is checked using isupper() and islower()
- The counts are updated accordingly
- The final dictionary is printed showing the case distribution


Written & researched by Dr. Shahin Siami