java program to return the no of vowels in a string code example
Example 1: output percentage of vowels and consonants in a given file in python
# Python Program to Count Vowels and Consonants in a String
str1 = input("Please Enter Your Own String : ")
vowels = 0
consonants = 0
for i in str1:
if(i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u'
or i == 'A' or i == 'E' or i == 'I' or i == 'O' or i == 'U'):
vowels = vowels + 1
else:
consonants = consonants + 1
print("Total Number of Vowels in this String = ", vowels)
print("Total Number of Consonants in this String = ", consonants)
Example 2: count vowels
vow = ['a', 'A', 'e',
'E', 'i', 'I',
'o', 'O', 'U',
'u', 'Y', 'y']
def vowels(str):
global vow
string = list(str)
count = 0
for i in range(len(string)):
if string[i] in vow:
count += 1
return count