I need help writing the following program in Python 3.2. Must fall with in the f
ID: 3538361 • Letter: I
Question
I need help writing the following program in Python 3.2.
Must fall with in the following requirements:
Main() to control logic.
Seperate function to count vowels and returns the count.
Seperate function to count consonants and returns the count.
Use loop to count vowels and consonants.
Use proper string method to determine if vowel or consonant.
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.
Explanation / Answer
def count_vowels(text):
c=0
text=text.lower()
for x in text:
if x in 'aeiou':
c=c+1
return c
def count_consonants(text):
c=0
text=text.lower()
for x in text:
if x not in 'aeiou' and str.isalpha(x):
c=c+1
return c
def main():
text=input("Enter String:")
vowels = count_vowels(text)
consonants = count_consonants(text)
print("Number of Vowels in inputted string is: "+str(vowels))
print("Number of Consonants in inputted string is: "+str(consonants))
main()