Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def dec2roman(num):
- if num>3999:
- return 'out of range'
- rnum = {
- '1': ['I','X','C','M'],
- '2': ['II','XX','CC','MM'],
- '3': ['III','XXX','CCC','MMM'],
- '4': ['VI','LX','DC'],
- '5': ['V','L','D'],
- '6': ['IV','XL','CD'],
- '7': ['IIV','XXL','CCD'],
- '8': ['IIIV','XXXL','CCCD'],
- '9': ['XI','CX','MD'],
- '0': ['','','']
- }
- numstr = str(num)[::-1]
- rstr = ''
- for i in range(len(numstr)):
- rstr += rnum[numstr[i:i+1]][i]
- return rstr[::-1]
- print(dec2roman(2345))
- print(dec2roman(456))
Add Comment
Please, Sign In to add comment