def intToRoman(num):
result = ""
roman_table = {1000: "M",900:"CM",500:"D",400:"CD",100:"C",90:"XC",50:"L",
40:"XL",10:"X",9:"IX",5:"V",4:"IV",1:"I"}
while num != 0:
for key,value in roman_table.items():
if num >= key:
dividend = int(num/key)
num %= key
result += dividend * value
return result
def romanToInt(s):
if s is None or s == '' or s == ' ':
return 0
roman_table = {'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000}
roman_integer = 0;
for i in range(len(s)):
if i > 0 and roman_table[s[i]] > roman_table[s[i-1]]:
roman_integer += roman_table[s[i]] - 2 * roman_table[s[i-1]]
else:
roman_integer += roman_table[s[i]]
return roman_integer
print(romanToInt("MI"))
print(intToRoman(8))