Advertisement
Guest User

Untitled

a guest
Dec 27th, 2024
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. def count_vowels_consonants(text="How many vowels and consonants are in this sentence?"):
  2.     vowels = {'a', 'e', 'i', 'o', 'u'}
  3.     vowels_count = 0
  4.     consonants_count = 0
  5.  
  6.     for char in text.lower():  # Handle case insensitivity
  7.         if char in vowels:
  8.             vowels_count += 1
  9.         elif char.isalpha():  # Check for alphabetic characters
  10.             consonants_count += 1
  11.  
  12.     return vowels_count, consonants_count
  13.  
  14. # Function call and result display
  15. vowels_count, consonants_count = count_vowels_consonants()
  16.  
  17. print(f"The number of vowels in the string is: {vowels_count}")
  18. print(f"The number of consonants in the string is: {consonants_count}")
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement