Logic Building
# Take digit
digit = int(input("Enter a digit (0-9): "))
# Map to word
words = ["Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"]
if 0 <= digit <= 9:
print(words[digit])
else:
print("Invalid digit")Output
Enter a digit (0-9): 5 Five Enter a digit (0-9): 0 Zero
Use list indexing to map digit to word.
Key Concepts:
- Create list of word forms
- Use digit as index
- Validate input range