Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by Chocolater
def checkio(data):
numbers = ''
while data >= 1000:
numbers = numbers + 'M'
data -= 1000
while data >= 900:
numbers = numbers + 'CM'
data -= 900
while data >= 500:
numbers = numbers + ('D')
data -= 500
while data >= 400:
numbers = numbers + ('CD')
data -= 400
while data >= 100:
numbers = numbers + ('C')
data -= 100
while data >= 90:
numbers = numbers + ('XC')
data -= 90
while data >= 50:
numbers = numbers + ('L')
data -= 50
while data >= 40:
numbers = numbers + ('XL')
data -= 40
while data >= 10:
numbers = numbers + ('X')
data -= 10
if data == 9:
numbers = numbers + ('IX')
if data == 8:
numbers = numbers + ('VIII')
if data == 7:
numbers = numbers + ('VII')
if data == 6:
numbers = numbers + ('VI')
if data == 5:
numbers = numbers + ('V')
if data == 4:
numbers = numbers + ('IV')
if data == 3:
numbers = numbers + ('III')
if data == 2:
numbers = numbers + ('II')
if data == 1:
numbers = numbers + ('I')
return numbers
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