Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Daily Python Projects
- Algorithm to Count Vowels and Consonants in a String
- Level 1: Beginner
- https://dailypythonprojects.substack.com/p/algorithm-to-count-vowels-and-consonants
- This program defines a string, counts how many vowels and consonants are present, and displays both counts.
- """
- vowels = ("a", "e", "i", "o", 'u')
- consonants = ("b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "ñ", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z")
- vowels_count = 0
- consonants_count = 0
- input_text = input('Enter your text: ').lower()
- for letter in input_text:
- if letter in vowels:
- vowels_count += 1
- elif letter in consonants:
- consonants_count += 1
- print(f'The text contain {vowels_count} vowels and {consonants_count} consonants')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement