Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Roman Numerals by aya.kanazawa
import math
def romans_for_certain_place(place_number, one_roman, five_roman, ten_roman):
romans = []
if place_number < 4:
romans += [one_roman for i in range(place_number)]
elif place_number == 4:
romans += [one_roman, five_roman]
elif place_number >= 5 and place_number <= 8:
romans += [five_roman]
romans += [one_roman for i in range(place_number - 5)]
elif place_number == 9:
romans += [one_roman, ten_roman]
return romans
def checkio(data):
thousands_place = math.floor(data / 1000)
hundreds_place = math.floor((data % 1000) / 100)
tens_place = math.floor((data % 100) / 10)
ones_place = data % 10
print((thousands_place,hundreds_place,tens_place,ones_place))
romans = ['M' for i in range(thousands_place)]
romans += romans_for_certain_place(hundreds_place, 'C', 'D', 'M')
romans += romans_for_certain_place(tens_place, 'X', 'L', 'C')
romans += romans_for_certain_place(ones_place, 'I', 'V', 'X')
return "".join(romans)
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'
print('Done! Go Check!')
April 25, 2019