πŸ”₯ LIVE πŸ‘©β€πŸ« Teachers: Host Live Tests  |  πŸŽ“ Students: Practice Class-wise Quizzes Go to Quiz Portal βž”

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

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)
>>>
Jitendra Singh
βœ” Verified Educator

Jitendra Singh

Founder of CBSEPython.in

I help CBSE Class 9–12 students learn Python, Information Technology, Artificial Intelligence and Computer Science through easy notes, quizzes, MCQs and sample papers.

Read More About Me β†’

Leave a Comment