Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def count_vowels_consonants(text="How many vowels and consonants are in this sentence?"):
- vowels = {'a', 'e', 'i', 'o', 'u'}
- vowels_count = 0
- consonants_count = 0
- for char in text.lower(): # Handle case insensitivity
- if char in vowels:
- vowels_count += 1
- elif char.isalpha(): # Check for alphabetic characters
- consonants_count += 1
- return vowels_count, consonants_count
- # Function call and result display
- vowels_count, consonants_count = count_vowels_consonants()
- print(f"The number of vowels in the string is: {vowels_count}")
- print(f"The number of consonants in the string is: {consonants_count}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement