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 digit
2digit = int(input("Enter a digit (0-9): "))
3
4# Map to word
5words = ["Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"]
6
7if 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