Python Different Counts in String – Python program to count uppercase letters, lower case letters, vowels, consonants and spaces in the given string.
#Python program to count upper case letters, lower case letters #vowels, consonants and spaces in a string uppercase=0 lowercase=0 vowels=0 consonants=0 spaces=0 string=input("Enter a String: ") for ch in string: if (ch.isupper()): uppercase+=1 if (ch.islower()): lowercase+=1 if (ch in ('A', 'a', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U')): vowels+=1 elif (ch.isalpha()): consonants+=1 if (ch.isspace()): spaces+=1 print("The given string contains...") print("%d Uppercase letters"%uppercase) print("%d Lowercase letters"%lowercase) print("%d Vowels"%vowels) print("%d Consonants"%consonants) print("%d Spaces"%spaces)
The Python program provides many conts of different types in a string. For example it will display the number of
- Uppercase letters
- Lowercase letters
- Vowels
- Consonants
- and Spaces
Output: Here is some sample output of this program run.
Enter a String: Hello World
The given string contains…
2 Uppercase letters
8 Lowercase letters
3 Vowels
7 Consonants
1 Spaces
- Python Program to convert string in Sentence case
- Python Program to convert string to Opposite case
- Python Program to Convert String to Title Case
- Python Program to convert a string to lower case
- Python Program to Convert String to Upper Case
- Python Program To Show Calendar of a Year
- Python Program to output Calendar for a month
- Palindrome Program in Python
- Python String Program To Count Vowels
- Python Text File Program To Count Vowels
- Python File Program Count Characters in Text File
- Python Exception Handling FileNotFoundError
- Python Text File Read and Show File Contents
- Python file program read numbers write squares