Converting Decimal Number lying between 1 to 3999 to Roman Numerals | Function to calculate roman equivalent ; Storing roman values of digits from 0 - 9 when placed at different places ; Converting to roman ; Driver code
def intToRoman ( num ) : NEW_LINE INDENT m = [ " " , " M " , " MM " , " MMM " ] NEW_LINE c = [ " " , " C " , " CC " , " CCC " , " CD " , " D " , " DC " , " DCC " , " DCCC " , " CM ▁ " ] NEW_LINE x = [ " " , " X " , " XX " , " XXX " , " XL " , " L " , " LX " , " LXX " , " LXXX " , " XC " ] NEW_LINE i = [ " " , " I " , " II " , " III " , " IV " , " V " , " VI " , " VII " , " VIII " , " IX " ] NEW_LINE thousands = m [ num // 1000 ] NEW_LINE hundereds = c [ ( num % 1000 ) // 100 ] NEW_LINE tens = x [ ( num % 100 ) // 10 ] NEW_LINE ones = i [ num % 10 ] NEW_LINE ans = ( thousands + hundereds + tens + ones ) NEW_LINE return ans NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT number = 3549 NEW_LINE print ( intToRoman ( number ) ) NEW_LINE DEDENT