Logic Building
# Take string input
s = input("Enter a string: ")
# Count consonants
vowels = "aeiouAEIOU"
count = 0
for char in s:
if char.isalpha() and char not in vowels:
count += 1
print(f"Number of consonants: {count}")Output
Enter a string: Hello Number of consonants: 3
Count alphabets that are not vowels.
Key Concepts:
- Check if character is alphabet
- Check if not a vowel
- Count consonants