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.
# 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)
Enter a string: Hello World!
Case analysis: {'UPPER-CASE': 2, 'LOWER-CASE': 8}
- 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