Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by wojtek96
def checkio(data):
r_n = ''
if data / 1000 >= 1:
r_n = r_n + 'M'*(data // 1000)
data = data - 1000 * (data // 1000)
if data / 1000 >= 0.9:
r_n = r_n + 'CM'
data = data - 900
if data / 500 >= 1:
r_n = r_n + 'D'
data = data - 500
if data / 1000 >= 0.4:
r_n = r_n + 'CD'
data = data - 400
if data / 100 >= 1:
r_n = r_n + 'C'*(data // 100)
data = data - 100 * (data // 100)
if data / 100 >= 0.9:
r_n = r_n + 'XC'
data = data - 90
if data / 50 >= 1:
r_n = r_n + 'L'
data = data - 50
if data / 100 >= 0.4:
r_n = r_n + 'XL'
data = data - 40
if data / 10 >= 1:
r_n = r_n + 'X' * (data // 10)
data = data - 10 * (data // 10)
if data / 10 >= 0.9:
r_n = r_n + 'IX'
data = data - 9
if data / 5 >= 1:
r_n = r_n + 'V'
data = data - 5
if data / 10 >= 0.4:
r_n = r_n + 'IV'
data = data - 4
if data / 1 >= 1:
r_n = r_n + 'I'*(data // 1)
data = data - 1 * (data // 1)
return r_n
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'
Dec. 15, 2016