(Solved) : Write Two Functions Python One Converts Number Roman Numeral Converttoroman Converts Back Q42722531 . . .

Write two functions in Python. One that converts a number to aRoman Numeral (convertToRoman), and the other converts it back to anumber(convertFromRoman).

I. Given a number, return a Roman Numeral string. (20points)

  1. Any number <= 0, throws “Error – Too Small”.
  2. Any number > 3,999, throws “Error – Too Large”.
  3. Any value that is not a number, throws “Error – Not aNumber”.
  4. Use standard values(en.wikipedia.org/wiki/Roman_numerals).

1 = I 7 = VII 40 = XL 100 = C 700 = DCC 74 = LXXIV

2 = II 8 = VIII 50 = L 200 = CC 800 = DCCC 299 = CCXCIX

3 = III 9 = IX 60 = LX 300 = CCC 900 = CM 2019 = MMXIX

4 = IV 10 = X 70 = LXX 400 = CD 1000 = M

5 = V 20 = XX 80 = LXXX 500 = D 2000 = MM

6 = VI 30 = XXX 90 = XC 600 = DC 3000 = MMM

Examples:

convertToRoman(812) returns “DCCCXII”

      convertToRoman(49) returns“XLIX”

      convertToRoman(5000) throws“Error – Too Large”

II. Given a Roman Numeral String, parse it and return thenumber. If it does not match a legal number from above (in therange 1 to 3,999), throw “Error”. (40 points)

Examples:

      convertFromRoman(“CCCXIV”)returns 314

      convertFromRoman(“MCMXCIX”)returns 1999

      convertFromRoman(“CXXXXI”) throws“Error”

      convertFromRoman(“ I ”) throws“Error”

      convertFromRoman(“MMMM”) throws“Error”

Expert Answer


Answer to Write two functions in Python. One that converts a number to a Roman Numeral (convertToRoman), and the other converts it…

Leave a Comment

About

We are the best freelance writing portal. Looking for online writing, editing or proofreading jobs? We have plenty of writing assignments to handle.

Quick Links

Browse Solutions

Place Order

About Us

× How can I help you?