Python Forum
Converting number to roman numerals
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Converting number to roman numerals
#4
From Wikipedia
https://en.wikipedia.org/wiki/Roman_numerals

Complete the code at (...) and you should be good to go.

:)

PS, of course it should be a class with converters, and the dictionary should be a class variable and etc. ...

def roman_numeral(n):

    dntor = {
        3000:'MMM',
        2000:'MM',
        1000:'M',
        900:'CM',
        800:'DCCC',
        700:'DCC',
        600:'DC',
        500:'D',
        400:'CD',
        300:'CCC',
        200:'CC',
        100:'C',
        90:'XC',
        80:'LXXX',
        70:'LXX',
        60:'LX',
        50:'L',
        40:'XL',
        30:'XXX',
        20:'XX',
        10:'X',
        9:'IX',
        8:'VIII',
        7:'VII',
        6:'VI',
        5:'V',
        4:'IV',
        3:'III',
        2:'II',
        1:'I',
        0:''
    }

    assert(0 < n < 4000)
    
    x = n%10
    rs = dntor[x]
    n -= x
    
    #...
    assert(n==0)

    return rs
Reply


Messages In This Thread
Converting number to roman numerals - by jagasrik - Aug-08-2020, 08:54 PM
RE: Converting number to roman numerals - by voidptr - Aug-09-2020, 07:45 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with implementation of the logic to convert roman numeral to integer jagasrik 2 2,352 Aug-14-2020, 07:31 PM
Last Post: deanhystad
  Roman Numeral Ordered List? (first post) CopperyMarrow15 1 1,762 Nov-06-2019, 11:06 PM
Last Post: Larz60+
Question [Help] Convert integer to Roman numerals? {Screenshot attached} vanicci 10 9,310 Aug-06-2018, 05:19 PM
Last Post: vanicci

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020