Check if Character is Vowel or Consonant
Take a character and check if it's a vowel or consonant.
BeginnerPhase 1 - Level 1: Simple ConditionsExample 9 of 10
check-if-character-is-vowel-or-consonant.py
1# Take a character as input2ch = input("Enter a character: ").lower()34# Check if vowel or consonant5if ch in 'aeiou':6 print("Vowel")7elif ch.isalpha():8 print("Consonant")9else:10 print("Not an alphabet")
Output
Enter a character: a Vowel Enter a character: b Consonant Enter a character: 5 Not an alphabet
What's going on
Check if character is a vowel or consonant.
Key Concepts:
Convert to lowercase for case-insensitive check
Check if character is in 'aeiou' for vowels
Use
isalpha() to check if it's an alphabetOtherwise, it's not an alphabet
🔗Related Content
- 📖
Phase 1 - Learn Concepts
Review Phase 1 concepts and explanations
- 📝
Phase 1 - Quiz
Test your Phase 1 understanding with quiz questions
- 💻
Phase 1 - All Practice Problems
Explore all practice problems for Phase 1
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum