Converting month numbers (1-12) to Roman numerals is a common requirement in data formatting, report generation, and calendar applications. Whether you're creating formal documents, building a date formatter, or working with legacy systems that use Roman numerals, Python makes this conversion straightforward.
This tutorial shows you multiple practical approaches to convert month numbers to Roman numerals, from simple dictionary lookups to algorithmic solutions.
1. Using a Dictionary Lookup (Simplest Method)
The most practical approach for month conversion uses a dictionary mapping. This method is fast, readable, and perfect for month-specific conversions.
def month_to_roman(month):
"""Convert month number (1-12) to Roman numeral"""
months_roman = {
1: 'I', 2: 'II', 3: 'III', 4: 'IV', 5: 'V', 6: 'VI',
7: 'VII', 8: 'VIII', 9: 'IX', 10: 'X', 11: 'XI', 12: 'XII'
}
return months_roman.get(month, 'Invalid month')
# Examples
print(month_to_roman(1)) # Output: I
print(month_to_roman(7)) # Output: VII
print(month_to_roman(12)) # Output: XII
Why use this method? It's the fastest and most efficient for months since you're working with a fixed set of 12 values. No complex calculations needed.
2. Using an Algorithmic Approach
For a more flexible solution that works beyond months, use the classic Roman numeral algorithm. This approach builds the numeral by subtracting values.
def int_to_roman(num):
"""Convert integer (1-3999) to Roman numeral"""
values = [
(10, 'X'), (9, 'IX'), (5, 'V'), (4, 'IV'), (1, 'I')
]
result = ''
for value, numeral in values:
count = num // value
if count:
result += numeral * count
num -= value * count
return result
# Convert months
print(int_to_roman(3)) # Output: III
print(int_to_roman(8)) # Output: VIII
print(int_to_roman(11)) # Output: XI
When to use this? Choose this method when you need to convert any integer to Roman numerals, not just months. It's reusable for years, days, or chapter numbers.
3. Using the roman Library (External Package)
For production applications, the roman library provides a well-tested, standardized solution.
# Install first: pip install roman
import roman
# Convert month numbers
print(roman.toRoman(1)) # Output: I
print(roman.toRoman(6)) # Output: VI
print(roman.toRoman(12)) # Output: XII
# Reverse conversion
print(roman.fromRoman('IX')) # Output: 9
Benefits: Built-in validation, bidirectional conversion, and handles edge cases automatically. Perfect for enterprise applications.
4. Date Formatting with Roman Numeral Months
Here's a practical example combining date formatting with Roman numeral months for formal documents.
from datetime import datetime
def format_date_roman(date):
"""Format date as DD.ROMAN.YYYY"""
months_roman = {
1: 'I', 2: 'II', 3: 'III', 4: 'IV', 5: 'V', 6: 'VI',
7: 'VII', 8: 'VIII', 9: 'IX', 10: 'X', 11: 'XI', 12: 'XII'
}
return f"{date.day}.{months_roman[date.month]}.{date.year}"
# Example usage
today = datetime(2026, 2, 14)
print(format_date_roman(today)) # Output: 14.II.2026
# Multiple dates
dates = [datetime(2026, 1, 15), datetime(2026, 7, 4), datetime(2026, 12, 25)]
for date in dates:
print(format_date_roman(date))
# Output:
# 15.I.2026
# 4.VII.2026
# 25.XII.2026
Common Use Cases
Report Generation: Financial reports often use Roman numerals for quarters and months
- Q.I.2026, Q.II.2026, etc.
Academic Documents: Citations and bibliography entries in formal writing
- "Published in Vol. XII, Issue III"
Legal Documents: Contract dates and version numbers
- "Effective date: 15.IX.2025"
Clock Faces: Digital clock displays and calendar widgets
- Traditional clock numerals I through XII
Archival Systems: Historical date formatting in databases and catalogs
Quick Reference Roman Months
| Month | Number | Roman |
|---|---|---|
| January | 1 | I |
| February | 2 | II |
| March | 3 | III |
| April | 4 | IV |
| May | 5 | V |
| June | 6 | VI |
| July | 7 | VII |
| August | 8 | VIII |
| September | 9 | IX |
| October | 10 | X |
| November | 11 | XI |
| December | 12 | XII |
Choosing the Right Method
- Need only months? → Use dictionary lookup (Method 1)
- Need any integer conversion? → Use algorithmic approach (Method 2)
- Production application? → Use
romanlibrary (Method 3) - Custom date formatting? → Combine with datetime (Method 4)
For most month-specific use cases, the simple dictionary approach is your best choice. It's readable, maintainable, and performs excellently. Save the algorithmic approach for when you need to convert arbitrary numbers beyond the 1-12 range.