This is the first coding class I've taken and I'm not getting much feedback from the instructor. The function of this program is to take two roman numeral inputs, convert them to arabic, add them together, then convert the sum to roman numerals. I wanted to see if any of you code ninjas could give me some feedback on the solution that I've come up with for this.
I would like to note that in the class I'm taking we haven't learned about dictionaries and we have only briefly covered lists.
This is only the functional part of the code, not including the loops to catch improper inputs.
print('Enter two roman numeral number to be added together')
print()
#converting first roman numeral to arabic
user1 = input('Enter first roman numeral: ')
print()
total1 = 0
for i in user1:
if i == 'I':
total1 += 1
elif i == 'V':
total1 += 5
elif i == 'X':
total1 += 10
elif i == 'L':
total1 += 50
elif i == 'C':
total1 += 100
if 'IV' in user1:
total1 -= 2
if 'IX' in user1:
total1 -= 2
if 'XL' in user1:
total1 -= 20
print('The decimal value of', user1, 'is', total1)
print()
#converting second roman numeral to arabic
user2 = input('Enter second roman numeral: ')
print()
total2 = 0
for i in user2:
if i == 'I':
total2 += 1
elif i == 'V':
total2 += 5
elif i == 'X':
total2 += 10
elif i == 'L':
total2 += 50
elif i == 'C':
total2 += 100
if 'IV' in user2:
total2 -= 2
if 'IX' in user2:
total2 -= 2
if 'XL' in user2:
total2 -= 20
print('The decimal value of', user2, 'is', total2)
print()
totalSum = total1 + total2
print('The decimal sum is:', totalSum)
print()
numeral = []
# converting from arabic to roman numeral
# splits the number into integers and appends roman numeral characters to a list
while totalSum > 1:
for i in range(len(str(totalSum))): #this loop to identify the one, tens, hundreds place
if i == 0:
digit = totalSum % 10
totalSum //= 10
if digit == 9:
numeral.append('IX')
if 5 < digit < 9:
numeral.append('I' * (digit % 5))
digit -= digit % 5
if digit == 5:
numeral.append('V')
if digit == 4:
numeral.append('IV')
if digit < 4:
numeral.append('I' * digit)
if i == 1:
digit = totalSum % 10
totalSum //= 10
if digit == 9:
numeral.append('XC')
if 5 < digit < 9:
numeral.append('X' * (digit % 5))
digit -= digit % 5
if digit == 5:
numeral.append('L')
if digit == 4:
numeral.append('XL')
if digit < 4:
numeral.append('X' * digit)
if i == 2:
digit = totalSum % 10
totalSum //= totalSum
numeral.append('C' * digit)
numeral.reverse()
print('The roman sum is: ', ''.join(numeral))