Guest User

Untitled

a guest
Jul 20th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. def int_to_roman(num):
  2. _values = [
  3. 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]
  4.  
  5. _strings = [
  6. '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"]
  7.  
  8. result = ""
  9. decimal = num
  10.  
  11. while decimal > 0:
  12. for algarism in range(len(_values)):
  13. if decimal >= _values[algarism]:
  14. if _values[algarism] > 1000:
  15. result += u'\u0304'.join(list(_strings[algarism])) + u'\u0304'
  16. else:
  17. result += _strings[algarism]
  18. decimal -= _values[algarism]
  19. break
  20. return result
  21.  
  22. print(int_to_roman(2000017))
Add Comment
Please, Sign In to add comment