Python one-liner to print Roman numerals
Here's an amusing little Python program to convert integers to Roman numerals:
def roman(n): print(chr(0x215F + n))
It only works if n is between 1 and 12. That's because Unicode contains characters for the Roman numerals I through XII.
Here are the characters it produces:
You may not be able to see these, depending on what fonts you have installed. I can see them in my browser, but when I ran the code above in a terminal window I only saw a missing glyph placeholder.
If you can be sure your reader can see the characters, say in print rather than on the web, the single-character Roman numerals look nice, and they make it clear that they're to be interpreted as Roman numerals.
Here's a screenshot of the symbols.
The post Python one-liner to print Roman numerals first appeared on John D. Cook.