20 lines
827 B
Python
20 lines
827 B
Python
|
def checkio(data):
|
||
|
mille = ['', 'M', 'MM', 'MMM']
|
||
|
centaine = ['', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM']
|
||
|
dixaine = ['', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC']
|
||
|
unite = ['', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX']
|
||
|
return mille[int(data / 1000)] + \
|
||
|
centaine[int(data % 1000 / 100)] + \
|
||
|
dixaine[int(data % 1000 % 100 / 10)] + \
|
||
|
unite[int(data % 1000 % 100 % 10)]
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
# These "asserts" using only for self-checking and not necessary for auto-testing
|
||
|
assert checkio(6) == 'VI', '6'
|
||
|
assert checkio(76) == 'LXXVI', '76'
|
||
|
assert checkio(499) == 'CDXCIX', '499'
|
||
|
assert checkio(3888) == 'MMMDCCCLXXXVIII', '3888'
|
||
|
assert checkio(3999) == 'MMMCMXCIX', '3999'
|
||
|
print('Done! Go Check!')
|