In this article, we will discuss the concept of the Python Program for count upper case or lowercase letter of the given string in Python language
In this post, we are going to learn how to count upper and lower case letters in a given string in Python programming language
The program allows to enter a String and it counts and displays whether the number of upper case and lower case letters of the given string using for loop in Python language
Program 1
#Python program to count upper case or lower case letter in given string str=input("Enter a string: ") upper=0 lower=0 for i in range(len(str)): #to lower case letter if(str[i]>='a' and str[i]<='z'): lower+=1 #to upper case letter elif(str[i]>='A' and str[i]<='Z'): upper+=1 print('Lower case letters= ',lower) print('Upper case letters=' ,upper)
When the above code is executed, it produces the following result
Enter a string: CodeForCoding Lower case letters= 10 Upper case letters= 3
Approach
The program allows to enter a String and it counts and displays whether the number of upper case and lower case letters of the given string using ASCII value in Python language
Program 2
str=input("Enter a string: ") upper=0 lower=0 for i in range(len(str)): #to lower case letter if(ord(str[i])>=97 and ord(str[i])<=122): lower+=1 #to upper case letter elif(ord(str[i])>=65 and ord(str[i])<=90): upper+=1 print('Lower case letters= ',lower) print('Upper case letters=' ,upper)
When the above code is executed, it produces the following result
Enter a string: Python Language Lower case letters= 12 Upper case letters= 2
Approach
The program allows to enter a String and it counts and displays whether the number of upper case and lower case letters of the given string using the predefined function in Python language
Program 3
str =input("Enter a string: ") upper=0 lower=0 for i in str: if (i.islower()): lower=lower+1 elif (i.isupper()): upper=upper+1 print("The lower case letters:",lower) print("The upper case letters:",upper)
When the above code is executed, it produces the following result
Enter a string: python The lower case letters: 5 The upper case letters: 1
Suggested for you
If statements in Python
Similar post
Java Program for count upper or lowercase letter of the given string
C Program for count upper or lowercase letter of the given string
Program for count upper or lowercase letter of the given string
Python Program for count upper or lowercase letter of the given string
Explanation of one dimensional array In this post, we will discuss the concept of "Explanation…
Python program to calculate the sum of odd and even numbers in a list In…
Python code to Calculate sum of odd and even in a list In this tutorial,…
How to find reverse number using method In this article, we will discuss the concept…
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…