Today, we are going to discuss a python program, which will print a string and count number of vowels in Python. The python program is to print a string and calculation of number of vowels ,which will be discussed. This basic python program is very useful for beginners, CBSE Class 11 and 12 Computer Science and Project Practical file.
String – A groups of alphabets and special characters included.
vowels- A vowel is in alphabets, these are the following – a,i,e,o,u
#WAP to print a string and the number of vowels present in it
Source Code and Execution of Program
st=input(“Enter the string”) #enter the string which you want to show and calculate vowels.
print(“Entered string =”,st) # The input string is shown as output
st=st.lower() #the string is lower casse and save in st
c=0 #vowel counter is set to zero
v=[‘a’,’e’,’i’,’o’,’u’] # vowels are these numbers a,e,i,o,u
for i in st: # for loop from starting of string to the last iteration with last character of string.
if i in v: #it checks whether the character is same as in v.
c+=1 #the characters increases in value 1,2,3 if character is a vowel.
print(“Number of vowels in entered string =”,c) Then the number of vowel string is shown with the number of vowel
Output of Printing a string and number of vowels in Python
Here we have given input string as – It is a good view of waterfall.
It first shows the string typed as output. Then calculate the number of vowels. which is 11.
Similarly the next string this way you look more beautiful is printed and the vowels are calculated which is 13.
Source code of WAP to print a string and the number of vowels present in it- click here
Thanks for reading this Python program to count number of vowels in a string.
For more python programs- click here