Program to count the vowels in a sentence in Python
In the python programming article, we are going to learn
-
program to count the number of vowels in a sentence in python
Program to count the number of vowels in a sentence in Python
The program is as follows:
# Owner : TutorialsInhand Author : Devjeet Roy
string = input("Enter a sentence: ").strip()
string = string.lower()
vowel_count = 0
for i in string:
if i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u':
vowel_count += 1
print("The number of vowels in the sentence is:", vowel_count)
The output of the program is as follows:
PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
Enter a sentence: lets learn python
The number of vowels in the sentence is: 4
Few important tips about the program
1. We ask the user to enter a sentence and then we evaluate the sentence to find the number of vowels present.
2. We transform the sentence to lower case to get rid of the distinct conditions for alphabets in capital letters and that in small letters.
Would you like to see your article here on tutorialsinhand.
Join
Write4Us program by tutorialsinhand.com
About the Author
Devjeet Roy
Full Stack Web Developer & Blockchain Enthusiast
Page Views :
Published Date :
Oct 13,2022