Count and display the number of vowels, consonants, uppercase, lowercase characters in string

 

# Vowels & Consonants count

str = input("Type the string: ")
vowel_count=0
consonants_count=0
vowel = set("aeiouAEIOU")
for alphabet in str:
  if alphabet in vowel:
    vowel_count=vowel_count +1
  elif alphabet == chr(32):
    consonants_count=consonants_count
  else:
    consonants_count=consonants_count+1
  
print("Number of Vowels in ",str," is :",vowel_count)
print("Number of Consonants in ",str," is :",consonants_count)

# Upper and lower case count

uppercase_count=0
lowercase_count=0
for elem in str:
  if elem.isupper():
    uppercase_count += 1
  elif elem.islower():
    lowercase_count += 1

print("Number of UPPER Case in ",str,"' is :",uppercase_count)
print("Number of lower case in ",str,"' is :",lowercase_count)

 

 

Output:

Type the string: "Welcome to cbsepython. Best website to learn cbse computer science"
('Number of Vowels in ', 'Welcome to cbsepython. Best website to learn cbse computer science', ' is :', 20)
('Number of Consonants in ', 'Welcome to cbsepython. Best website to learn cbse computer science', ' is :', 37)
('Number of UPPER Case in ', 'Welcome to cbsepython. Best website to learn cbse computer science', "' is :", 2)
('Number of lower case in ', 'Welcome to cbsepython. Best website to learn cbse computer science', "' is :", 54)
>>>
Copywrite © 2020-2024, CBSE Python,
All Rights Reserved
error: Content is protected !!