Question: Convert a Roman number to its decimal number presentation (USING PYTHON) USE DEF FUNCTION AND DICTIONARY Write a program that converts a Roman number such

Convert a Roman number to its decimal number presentation (USING PYTHON)

USE DEF FUNCTION AND DICTIONARY

Write a program that converts a Roman number such as MCMLXXVIII to its decimal number representation. Note: First write a function that yields the numeric value of each of the letters. Then use the following algorithm.

--------------------------------------------------------------------------------------------------------------------------------------------------------------

total = 0

While the roman number string is not empty

If value(first character) is at least value(second character), or the string has length 1

Add value(first character) to total.

Remove the first character.

Else

Add the difference, value(second character) - value(first character), to total.

Remove both characters.

--------------------------------------------------------------------------------------------------------------------------------------------------------------

You shall create the following two functions:

def convertDigit(a _roman _char ): returns the decimal value of the roman digit --> This function only accepts a single digit !

def romanToDecimal( roman_chars ): returns the decimal value

Your program shall test the function with the following code:

print(romanToDecimal("C"))

print(romanToDecimal("MCMLXXVIII"))

print(romanToDecimal("MMMCMXCIX"))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!