Mastodon Feed: Post

Mastodon Feed

Reblogged by jsonstein@masto.deoan.org ("Jeff Sonstein"):

linuxgal@techhub.social ("🌈 ☯️Teresita🐧👭") wrote:

Roman numerals with #Python #P35

#!/usr/bin/python3

import sys
x=int(sys.argv[1])
anums = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
rnums = "M CM D CD C XC L XL X IX V IV I".split()
ret = []
for a,r in zip(anums, rnums):
n,x = divmod(x,a)
ret.append(r*n)
print (''.join(ret))

Attachments: