Count Consonants
Count number of consonants in string.
BeginnerPhase 5 - Category 1: Basic String HandlingExample 6 of 10
count-consonants.py
1# Take string input2s = input("Enter a string: ")34# Count consonants5vowels = "aeiouAEIOU"6count = 07for char in s:8 if char.isalpha() and char not in vowels:9 count += 11011print(f"Number of consonants: {count}")
Output
Enter a string: Hello Number of consonants: 3
What's going on
Count alphabets that are not vowels.
Key Concepts:
Check if character is alphabet
Check if not a vowel
Count consonants
🔗Related Content
- 📖
Phase 5 - Learn Concepts
Review Phase 5 concepts and explanations
- 📝
Phase 5 - Quiz
Test your Phase 5 understanding with quiz questions
- 💻
Phase 5 - All Practice Problems
Explore all practice problems for Phase 5
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum