Python Program To Check Vowel or Consonant | check if string contains vowels python

In this post, we will make a python program that checks the number of vowels and consonants in the given sentences.

To check the number of vowels in a sentence then we have followed the following steps:

  1. So, First, we have to take input from the user, so, we use the input() function.
  2. Now, first, we convert all the letters into lower case.
  3. And then we make 2 variables vowels and consonants and set them to 0.
  4. And now, we make a list that contains all the vowels such as a, e, i, o, u.
  5. And then we iterate the string that was input by the user.
  6. Now, we check the letters of the strings are equal to the vowels that contain sin lists, if they equal then we update the vowels to plus+1.
  7. Otherwise, we update the consonant to plus 1.

Video Explanation of this program:



Program:

string = input("Enter any Strings: ")
sentence = string.lower()
vowels = 0
consonants = 0 
list = ["a","e","i","o","u"]
for letters in sentence:
    if letters in list:
        vowels +=1
    else:
        consonants +=1
    

print("Number of vowels in strings:"vowels)
print("NUmber of consonants in strins:"consonants)

Output:

Enter any Strings: papu master
Number of vowels in strings: 4
NUmber of consonants in strins: 7


Next Post Previous Post
No Comment
Add Comment
comment url