Write a python program to Count and display the number of vowels consonants, uppercase, lowercase characters in string
This python program allows the user to enter a string. Next, it counts the total number of vowels,consonants,uppercase,lowercase characters inside this string using For Loop.
This python program counts number of vowels and consonants from user specified string. It also counts number of uppercase and lower case letter if present in user entered string.At the end it returns total number of vowels,consonants,uppercase and lowercase letter in numbers.
Below is source code
s = input("Enter any string :")
vowel = consonent = uppercase = lowercase= 0
for i in s:
if(i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u'or i == 'A' or i == 'E' or i == 'I' or i == 'O' or i == 'U'):
vowel = vowel +1
else:
consonent = consonent + 1
if i.isupper() :
uppercase = uppercase + 1
if i.islower():
lowercase = lowercase + 1
print("Total number of vowel:",vowel)
print("Total number of consonent:",consonent)
print("Total number of uppercase letter:",uppercase)
print("Total number of lowercase letter:",lowercase)
Output:
>>> %Run 'count vowelconsonet.py' Enter any string :python Total number of vowel: 1 Total number of consonent: 5 Total number of uppercase letter: 0 Total number of lowercase letter: 6 >>> %Run 'count vowelconsonet.py' Enter any string :Sumedh Total number of vowel: 2 Total number of consonent: 4 Total number of uppercase letter: 1 Total number of lowercase letter: 5
Explanation
Here, we used Python For Loop to iterate each character in a String. Inside the for loop, we used if statement to check whether the character is a, e, i, o, u, A, E, I, O, U. If true, vowel is incremented value otherwise,consonant value is incremented.
We used if statement to check whether character is lowercase letter or uppercase letter. If character is in upper case letter then uppercase is incremented by 1. Lowercase value is incremented by 1 if character is in lower case
Python program to Count and display the number of vowels consonants, uppercase, lowercase characters and digits in string
This program uses ASCII values to find vowels and consonants and uses python inbuilt string function to find upper case and lowercase letter. It also check whether string contains digit or alphabets. If User specified string contain alphabets and numbers then it shows mixed string otherwise it counts total number of digits , uppercase and lowercase letters.
This python program counts number of vowels and consonants from user specified string. It also counts number of uppercase and lower case letter and digits if present in user entered string.At the end it returns total number of vowels,consonants,uppercase and lowercase letter and digits in numbers.
Below is Source code
s = input("Enter any string :")
vowels = consonents = uppercase = lowercase= digit = 0
for i in s:
if(ord(i) == 65 or ord(i) == 69 or ord(i) == 73
or ord(i) == 79 or ord(i) == 85
or ord(i) == 97 or ord(i) == 101 or ord(i) == 105
or ord(i) == 111 or ord(i) == 117):
vowels = vowels + 1
elif((ord(i) >= 97 and ord(i) <= 122) or (ord(i) >= 65 and ord(i) <= 90)):
consonents = consonents + 1
if i.isupper() :
uppercase = uppercase + 1
elif i.islower():
lowercase = lowercase + 1
elif i.isdigit() :
digit = digit + 1
else :
print("It is a mixed string")
print("Total number of vowel:",vowels)
print("Total number of consonent:",consonents)
print("Total number of uppercase letter:",uppercase)
print("Total number of lowercase letter:",lowercase)
print("Total number of digit:",digit)
Output:
>>> %Run 'count vowelconsonet.py' Enter any string :SUMedh Dixit 123 It is a mixed string Total number of vowel: 4 Total number of consonent: 7 Total number of uppercase letter: 4 Total number of lowercase letter: 7 Total number of digit: 3 >> %Run 'count vowelconsonet.py' Enter any string :Athang DIXIt 12345678 It is a mixed string It is a mixed string Total number of vowel: 4 Total number of consonent: 7 Total number of uppercase letter: 5 Total number of lowercase letter: 6 Total number of digit: 8 >>> %Run 'count vowelconsonet.py' Enter any string :123456789 Telehpne It is a mixed string Total number of vowel: 3 Total number of consonent: 5 Total number of uppercase letter: 1 Total number of lowercase letter: 7 Total number of digit: 9
Below is snapshot of above code

