fork download
  1. # Convert decimal number lying between 1-3999 to roman numerals
  2. # SYMBOL VALUE
  3. # I 1
  4. # II 2
  5. # III 3
  6. # IV 4
  7. # V 5
  8. # X 10
  9. # L 50
  10. # C 100
  11. # D 500
  12. # M 1000
  13.  
  14. def roman(n):
  15. num = [1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000]
  16. symbol = ["I", "IV", "V", "IX", "X", "XL", "L", "XC", "C", "CD", "D", "CM", "M"]
  17. i = 12
  18. while n:
  19. div = n//num[i]
  20. n%=num[i]
  21.  
  22. while div:
  23. print(symbol[i])
  24. div -=1
  25. i-=1
  26.  
  27.  
  28. n = int(raw_input())
  29. print (roman(n))
Success #stdin #stdout 0.02s 7184KB
stdin
99
stdout
XC
IX
None