Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Simple solution in Clear category for Roman Numerals by checinski.szymon
def getRomanValue(times, ones, fives, tens):
result = ""
if times < 4:
for i in range(0, times):
result += ones
elif times == 4:
result += ones + fives
elif times < 9:
result += fives
times -= 5
for i in range(0, times):
result += ones
else:
result += ones + tens
return result
def checkio(data):
#replace this for solution
result = ""
thousands = data // 1000
if thousands != 0:
for i in range (0, thousands):
result += "M"
data -= thousands * 1000
hundreds = data // 100
if hundreds != 0:
result += getRomanValue(hundreds, "C", "D", "M")
data -= hundreds * 100
tens = data // 10
if tens != 0:
result += getRomanValue(tens, "X", "L", "C")
data -= tens * 10
if data != 0:
result += getRomanValue(data, "I", "V", "X")
return result
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'
Oct. 22, 2016