The question itself is two parts, first part is to make a function of int_to_roman(num)
that converts integers into their roman numerical counterparts, just displaying them. The second part is to use that code and make a function called sum_roman
that takes a decimal integer as an input and returns the summation table of roman numbers corresponding to the decimal integers from 1 up to the number inputted.
I did a code for the first part in the form of:
class py_solution:
def int_to_Roman(self, num):
val = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
syb = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"]
roman_num = ''
a = 0
while num > 0:
for _ in range(num // val[a]):
roman_num += syb[a]
num -= val[a]
a += 1
return roman_num
This code worked for the first part giving me the roman numerials but I haven't been able to find anything that works for part 2, as I don't know the code to calculate all roman numerial up to that point or to make them into a table.