Write a program with a function that accepts a string as an argument and returns the number of vowels that the string contains. The application should have another function that accepts a string as an argument and returns the number of consonants that the string contains.
The application should let the user enter a string and should display the number of vowels and the number of consonants it contains.
Sample output:
Enter a string: california
The string you entered includes 5 vowels and 5 consonants
#Function to count consonents
def Consonents(s):
Count=0
vowels = ["A","E","I","O","U","a","e","i","o","u"]
for r in range(0,len(s)):
for c in range(0,len(s[r])):
if s[r][c] in vowels:
Count=Count+1
return(len(s)-Count)
#Function to count vowels
def VowelCounts(s):
Count=0
vowels = ["A","E","I","O","U","a","e","i","o","u"]
for r in range(0,len(s)):
for c in range(0,len(s[r])):
if s[r][c] in vowels:
Count=Count+1
return(Count)
InputStr = input("Enter a string: ")
print("The string you entered contains %d vowels and %d consonents"%(VowelCounts(InputStr),Consonents(InputStr)))
Comments