Check Letter, Digit, or Neither
Take a character and check if it is a letter, a digit, or neither.
IntermediatePhase 1 - Level 4: Logical Operators & Compound StatementsExample 1 of 10
check-letter-digit-or-neither.py
1# Take character2ch = input("Enter a character: ")34# Check type5if ch.isalpha():6 print("Letter")7elif ch.isdigit():8 print("Digit")9else:10 print("Neither")
Output
Enter a character: a Letter Enter a character: 5 Digit Enter a character: @ Neither
What's going on
Use string methods to check character type.
Key Concepts:
isalpha(): checks if letter
isdigit(): checks if digit
Otherwise: special character
🔗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