Print Digit Word
Take a single digit (0-9) and print its word form ("Zero" to "Nine").
IntermediatePhase 1 - Level 4: Logical Operators & Compound StatementsExample 7 of 10
print-digit-word.py
1# Take digit2digit = int(input("Enter a digit (0-9): "))34# Map to word5words = ["Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"]67if 0 <= digit <= 9:8 print(words[digit])9else:10 print("Invalid digit")
Output
Enter a digit (0-9): 5 Five Enter a digit (0-9): 0 Zero
What's going on
Use list indexing to map digit to word.
Key Concepts:
Create list of word forms
Use digit as index
Validate input range
🔗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