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:
- So, First, we have to take input from the user, so, we use the input() function.
- Now, first, we convert all the letters into lower case.
- And then we make 2 variables vowels and consonants and set them to 0.
- And now, we make a list that contains all the vowels such as a, e, i, o, u.
- And then we iterate the string that was input by the user.
- 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.
- Otherwise, we update the consonant to plus 1.
Video Explanation of this 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:
print("Number of vowels in strings:", vowels)
print("NUmber of consonants in strins:", consonants)
Enter any Strings: papu master
Number of vowels in strings: 4
NUmber of consonants in strins: 7