Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by johankor
def checkio(data):
one={0:"",1:"I", 2:"II", 3:"III",4:"IV",5:"V",6:"VI",7:"VII",8:"VIII",9:"IX"}
ten={0:"", 1:"X", 2:"XX", 3:"XXX",4:"XL",5:"L",6:"LX",7:"LXX",8:"LXXX",9:"XC"}
hun={0:"",1:"C", 2:"CC", 3:"CCC", 4:"CD", 5:"D", 6:"DC", 7:"DCC", 8:"DCCC", 9:"CM"}
thou={0:"", 1:"M", 2:"MM", 3:"MMM"}
first= thou[(data // 1000)]
second= hun[(data // 100)%10]
third= ten[(data // 10) %10]
fourth= one[data % 10]
return f'{first}{second}{third}{fourth}'
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'
print('Done! Go Check!')
April 22, 2019
Comments: