Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by krzysztofc10
def checkio(data):
dataLength = len(str(data))
if dataLength == 1:
return(first(data))
if dataLength == 2:
data = str(data)
first1 = data[1]
second1 = data[0]
return(second(int(second1)) + first(int(first1)))
if dataLength == 3:
data = str(data)
first2 = data[2]
second2 = data[1]
third2 = data[0]
return(third(int(third2)) + second(int(second2)) + first(int(first2)))
if dataLength == 4:
data = str(data)
first3 = data[3]
second3 = data[2]
third3 = data[1]
fourth3 = data[0]
return(fourth(int(fourth3)) + third(int(third3)) + second(int(second3)) + first(int(first3)))
def first(data):
if data==0:
return("")
if data%9==0:
return("IX")
if data%8==0:
return("VIII")
if data%7==0:
return("VII")
if data%6==0:
return("VI")
if data%5==0:
return("V")
if data%4==0:
return("IV")
if data%3==0:
return("III")
if data%2==0:
return("II")
if data%1==0:
return("I")
def second(data):
if data==0:
return("")
if data%9==0:
return("XC")
if data%8==0:
return("LXXX")
if data%7==0:
return("LXX")
if data%6==0:
return("LX")
if data%5==0:
return("L")
if data%4==0:
return("XL")
if data%3==0:
return("XXX")
if data%2==0:
return("XX")
if data%1==0:
return("X")
def third(data):
if data==0:
return("")
if data%9==0:
return("CM")
if data%8==0:
return("DCCC")
if data%7==0:
return("DCC")
if data%6==0:
return("DC")
if data%5==0:
return("D")
if data%4==0:
return("CD")
if data%3==0:
return("CCC")
if data%2==0:
return("CC")
if data%1==0:
return("C")
def fourth(data):
if data==0:
return("")
if data%3==0:
return("MMM")
if data%2==0:
return("MM")
if data%1==0:
return("M")
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'
Jan. 16, 2018