Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def int_to_roman(num):
- _values = [
- 1000000, 900000, 500000, 400000, 100000, 90000, 50000, 40000, 10000, 9000, 5000, 4000, 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
- _strings = [
- 'M', 'C', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"]
- result = ""
- decimal = num
- while decimal > 0:
- for algarism in range(len(_values)):
- if decimal >= _values[algarism]:
- if _values[algarism] > 1000:
- result += u'\u0304'.join(list(_strings[algarism])) + u'\u0304'
- else:
- result += _strings[algarism]
- decimal -= _values[algarism]
- break
- return result
- print(int_to_roman(2000017))
Add Comment
Please, Sign In to add comment