Python program to count the number of lowercase and uppercase characters in a given string

Published by user on

In this post, we will see how to count the number of lowercase and uppercase characters in a given string.
Algorithm
Step 1: Declare a string in a variable.
Step 2: Initialize 2 count variables to 0
Step 3: Use a for loop to iterate over the string, here we will use isUpper() and isLower() function to identify if the character is in the upper case of the lower case. If we get a lowercase character we will increment lowerCaseCount variable by 1 and if we get the upper case character, we will increment upperCaseCount variable by 1.
Step 4: After completing the for loop, we will print the values of upperCaseCount and lowerCaseCount variable.
Step 5: End
Example

Input: "This is a Python Prgram"
Output:
The Number of lowercase characters found in the provided string: 16
The Number of uppercase characters found in the provided string: 3

Program

string="This is a Python Prgram"
lowerCaseCharCount=0
upperCaseCharCount=0
for i in string:
      if(i.islower()):
            lowerCaseCharCount=lowerCaseCharCount+1
      elif(i.isupper()):
            upperCaseCharCount=upperCaseCharCount+1
print("The Number of lowercase characters found in the provided string:")
print(lowerCaseCharCount)
print("The Number of uppercase characters found in the provided string:")
print(upperCaseCharCount)

Output

The Number of lowercase characters found in the provided string: 
16
The Number of uppercase characters found in the provided string: 
3
Categories: python