Advertisement
Edwinlga

count_vowels_consonants.py

Feb 7th, 2025 (edited)
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | Source Code | 0 0
  1. """
  2. Daily Python Projects
  3. Algorithm to Count Vowels and Consonants in a String
  4. Level 1: Beginner
  5. https://dailypythonprojects.substack.com/p/algorithm-to-count-vowels-and-consonants
  6.  
  7. This program defines a string, counts how many vowels and consonants are present, and displays both counts.
  8.  
  9. """
  10. vowels = ("a", "e", "i", "o", 'u')
  11. consonants = ("b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "ñ", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z")
  12. vowels_count = 0
  13. consonants_count = 0
  14.  
  15. input_text = input('Enter your text: ').lower()
  16. for letter in input_text:
  17.     if letter in vowels:
  18.         vowels_count += 1
  19.     elif letter in consonants:
  20.         consonants_count += 1
  21.  
  22. print(f'The text contain {vowels_count} vowels and {consonants_count} consonants')
Tags: python
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement