Here is a possible implementation of the two functions:
pythondef roman_to_arabic(s: str):
"""
converts a uppercase Roman number represented as a string to an Arabic number represented as an integer
"""
# ensure that the string is a valid Roman number
if not s.isupper():
raise ValueError("Invalid Roman number")
# get the index of the first occurrence of the number
i = s.find(".", i)
# check if the current index is after the last occurrence of the number
if i < len(s) - 4:
raise ValueError("Invalid Roman number")
# get the actual number
n = s[i+1:i+4]
# convert the number to an integer
return int(n)
def arabic_to_roman(n: int):
"""
converts an Arabic number represented as an integer to a uppercase Roman number represented as a string
"""
# ensure that the integer is a valid Arabic number
if n < 0 or n > 459:
raise ValueError("Invalid Arabic number")
# get the index of the first occurrence of the number
i = n // 10
# get the rest of the number
num_str = n % 10
# check if the current index is after the last occurrence of the number
if i < num_str.find(".", i) < len(num_str):
raise ValueError("Invalid Arabic number")
# convert the rest of the number to a string
num_str = num_str[i:]
# convert the string to an uppercase Roman number
return str(num_str)[::-1].upper()
Note that this implementation assumes that the input string is a valid Roman number, that it starts with a ., and that it has at least four characters. If the input string is not a valid Roman number or if it does not have at least four characters, the function will raise a ValueError exception.