I\'m trying to write a code that converts a user-inputted integer into its Roman numeral equivalent. What I have so far is:
The point of the generate_
start subtracting 1000,900... to 1 from A and stops when it finds positive.add corresponding roman to ans and make A to A-i where i is (1,4,5,9,10.....) repeat while A does not become 0.
def intToRoman(self, A):
l=[[1,'I'],[4,'IV'],[5,'V'],[9,'IX'],[10,'X'],[40,'XL'],[50,'L'],
[90,'XC'],[100,'C'],[400,'CD'],[500,'D'],[900,'CM'],[1000,'M']]
ans=""
while(A>0):
for i,j in l[::-1]:
if A-i>=0:
ans+=j
A=A-i
break
return ans