Find total number of lowercase characters in a string using Python 3

Find number of lowercase characters in a String using Python 3:

In this python tutorial, we will learn how to find total number of lowercase characters in a string . Algorithm used in this program is :

Algorithm :

1. First take the string from the user
2. Initialize one counter as ‘0’. This counter will store the total count of lowercase characters.
3. Iterate through the string character by character.
4. Check for each character if it is lowercase or uppercase.
5. If lowercase, increment the counter by one
6. Finally check if the counter is more than ‘0’. If it is more than ‘0’, print the number . If it is less than ‘0’, print that ‘No lowercase Character found.’

Python 3 Program :

input_string = input("Enter a string : ")

count = 0

for c in input_string:
	if(c.islower()):
		count = count + 1

if(count == 0):
	print("No Lower case character found in the string.")
else :
	print("Total no of lower case character : ",count)

Explaination of the program:

1. First,take the string input from user using ‘input()’
2. save the input in a variable ‘input_string’
3. use a ‘for’ loop to scan character by character of the string
4. Check if a character is lowercase using ‘.islower()’ method.
5. If it is ‘true’, increment the ‘count’ value. It should be initialized with value ‘0’.
6. After the ‘for’ loop is completed, check if ‘count’ is ‘0’ or more than ‘0’. If ‘0’, that means no lower case character is found. Print the value of ‘count’ if it is more than ‘0’.

Example program :

Enter a string : THIS IS A STRING
No Lower case character found in the string.

Enter a string : Hello World
Total no of lower case character :  8
Sitewide-USD 336x280

Leave a Reply