Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
When you can't think of an easier way.... solution in Clear category for Roman Numerals by Adrian_Goh
def checkio(data):
th = data // 1000
hu = data % 1000 // 100
te = data % 100 // 10
un = data % 10
rom = ""
rom += "M"*th
if hu == 9:
rom += "CM"
elif hu >= 5:
rom += "D" + "C"*(hu-5)
elif hu == 4:
rom += "CD"
else:
rom += "C" * hu
if te == 9:
rom += "XC"
elif te >= 5:
rom += "L" + "X"*(te-5)
elif te == 4:
rom += "XL"
else:
rom += "X" * te
if un == 9:
rom += "IX"
elif un >= 5:
rom += "V" + "I"*(un-5)
elif un == 4:
rom += "IV"
else:
rom += "I" * un
return rom
#replace this for solution
return ""
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!')
Jan. 23, 2021
Comments: