Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by Lukeram
def setki(argument):
switcher = {
0: "",
1: "C",
2: "CC",
3: "CCC",
4: "CD",
5: "D",
6: "DC",
7: "DCC",
8: "DCCC",
9: "CM",
}
return switcher.get(argument, "")
def dzies(argument):
switcher = {
0: "",
1: "X",
2: "XX",
3: "XXX",
4: "XL",
5: "L",
6: "LX",
7: "LXX",
8: "LXXX",
9: "XC",
}
return switcher.get(argument, "")
def jedn(argument):
switcher = {
0: "",
1: "I",
2: "II",
3: "III",
4: "IV",
5: "V",
6: "VI",
7: "VII",
8: "VIII",
9: "IX",
}
return switcher.get(argument, "")
def checkio(data):
i = data
str = ""
while i:
str = str + "M"*( i // 1000 )
i = i - ( i // 1000 * 1000 )
str = str + setki( i // 100 )
i = i - ( i // 100 * 100 )
str = str + dzies( i // 10 )
i = i - ( i // 10 * 10 )
str = str + jedn( i )
i = i-i
#replace this for solution
return str
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'
Nov. 9, 2016