I need to convert a roman numeral string into an integer. I have NO clue how to even start, only that I need to use the regex.
import re
def romanNumeralToInt(romanNum):
romanNum = romanNum.upper()
totalValue = 0
I do have a series of tests that it should past:
def test():
print("Tests started.")
x = "III"
"" if romanNumeralToInt(x) == 3 else print(x + " - " + str(romanNumeralToInt(x)))
x = "IV"
"" if romanNumeralToInt(x) == 4 else print(x + " - " + str(romanNumeralToInt(x)))
x = "IX"
"" if romanNumeralToInt(x) == 9 else print(x + " - " + str(romanNumeralToInt(x)))
x = "C"
"" if romanNumeralToInt(x) == 100 else print(x + " - " + str(romanNumeralToInt(x)))
x = "CC"
"" if romanNumeralToInt(x) == 200 else print(x + " - " + str(romanNumeralToInt(x)))
x = "CCC"
"" if romanNumeralToInt(x) == 300 else print(x + " - " + str(romanNumeralToInt(x)))
x = "CD"
"" if romanNumeralToInt(x) == 400 else print(x + " - " + str(romanNumeralToInt(x)))
x = "D"
"" if romanNumeralToInt(x) == 500 else print(x + " - " + str(romanNumeralToInt(x)))
x = "DC"
"" if romanNumeralToInt(x) == 600 else print(x + " - " + str(romanNumeralToInt(x)))
x = "DCC"
"" if romanNumeralToInt(x) == 700 else print(x + " - " + str(romanNumeralToInt(x)))
x = "DCCC"
"" if romanNumeralToInt(x) == 800 else print(x + " - " + str(romanNumeralToInt(x)))
x = "M"
"" if romanNumeralToInt(x) == 1000 else print(x + " - " + str(romanNumeralToInt(x)))
x = "LXI"
"" if romanNumeralToInt(x) == 61 else print(x + " - " + str(romanNumeralToInt(x)))
x = "IC"
"" if romanNumeralToInt(x) == 99 else print(x + " - " + str(romanNumeralToInt(x)))
x = "MMCI"
"" if romanNumeralToInt(x) == 2101 else print(x + " - " + str(romanNumeralToInt(x)))
print("Tests ended.")