Write a program to read a string containing letters, each of which may be in either uppercase or lowercase, and return a tuple containing the number of vowels and consonants in the string in python
Code
def count_vowels_consonants(s):vowels = "aeiou"count_vowels = 0count_consonants = 0for char in s.lower():if char in vowels:count_vowels += 1elif char.isalpha():count_consonants += 1return (count_vowels, count_consonants)if __name__ == "__main__":s = input("Enter a string: ")count_vowels, count_consonants = count_vowels_consonants(s)print("Vowels: %d Consonants: %d" % (count_vowels, count_consonants))
0 Comments
Post a Comment