(Solved) : 6 Roman Ish Numerals Roman Numerals Slightly Tricky Letter Used 3 Times 4 Isn T Iiii S Iv Q44052415 . . .
Please give detailed explanations beside every code.
6. Roman-ish numerals Roman numerals are slightly tricky: the same letter should not be used more than 3 times, so 4 isn’t IIII, it’s IV. In this part of the question, however, we will be lazy: we can use the same letter up to 4 times. Write a Python function romanish that takes an integer smaller than 1000 and returns a string representation in this lazy form of Roman numerals. Example: • romanish(1) == ‘I’ • romanish(5) == ‘V’ • romanish(9) == ‘VIIII • romanish(39) == ‘XXXVIIII • romanish(50) == ‘L’ • romanish(100) == ‘C’ • romanish(500) == ‘D’ Try to do this question using a list/tuple. Hint: this is not too different from ”making change”. 7. Roman numerals, the full version Write a function that converts an integer to its true Roman numeral representation: Write a Python function roman(n) that takes an integer and returns a string represen- tation. Try to use lists or dictionaries! Example: • roman(1) == ‘I’ • roman(5) == ‘V’ • roman(9) == ‘IX’ • roman(39) == ‘XXXIX’ • roman(50) == ‘L’ • roman(100) == ‘C’ • roman(500) == ‘D’ • roman(999) == ‘CMXCIX’ Show transcribed image text 6. Roman-ish numerals Roman numerals are slightly tricky: the same letter should not be used more than 3 times, so 4 isn’t IIII, it’s IV. In this part of the question, however, we will be lazy: we can use the same letter up to 4 times. Write a Python function romanish that takes an integer smaller than 1000 and returns a string representation in this lazy form of Roman numerals. Example: • romanish(1) == ‘I’ • romanish(5) == ‘V’ • romanish(9) == ‘VIIII • romanish(39) == ‘XXXVIIII • romanish(50) == ‘L’ • romanish(100) == ‘C’
• romanish(500) == ‘D’ Try to do this question using a list/tuple. Hint: this is not too different from ”making change”. 7. Roman numerals, the full version Write a function that converts an integer to its true Roman numeral representation: Write a Python function roman(n) that takes an integer and returns a string represen- tation. Try to use lists or dictionaries! Example: • roman(1) == ‘I’ • roman(5) == ‘V’
• roman(9) == ‘IX’ • roman(39) == ‘XXXIX’ • roman(50) == ‘L’ • roman(100) == ‘C’ • roman(500) == ‘D’ • roman(999) == ‘CMXCIX’
Expert Answer
Answer to 6. Roman-ish numerals Roman numerals are slightly tricky: the same letter should not be used more than 3 times, so 4 isn…
OR