My goal is to get the user to input two roman numerals between I and V and to add them together. I want to display the equation in both decimal values and their roman numeral equivalents.
However, when ever I put values other than I and V, the value gets assigned 'NoneType', and program fails. I've tried setting the returns to str() and then calling int() later, setting roman num is '': num_value = # and then returning num_value at the end, but none of it has worked.
I think I'm missing something very fundamental, and it has to do with differentiating between values with repeating characters, such as 'I' (which is ok) and 'II' which gets assigned NoneType.
firstNumeral = input("please enter a roman numeral between I and V: ")
secondNumeral = input('please enter a second roman numeral between I and V: ')
def get_user_num(roman_num):
if roman_num is 'I':
return int(1)
elif roman_num is 'II':
return int(2)
elif roman_num is 'III':
return int(3)
elif roman_num is 'IV':
return int(4)
elif roman_num is 'V':
return int(5)
elif roman_num is 'VI':
return int(6)
elif roman_num is 'VII':
return int(7)
elif roman_num is 'VIII':
return int(8)
elif roman_num is 'IX':
return int(9)
elif roman_num is 'X':
return int(10)
firstNumber = get_user_num(firstNumeral)
secondNumber = get_user_num(secondNumeral)
totalNumber = firstNumber + secondNumber
def get_roman_number(result_number):
if result_number == 1:
return "I"
elif result_number == 2:
return "II"
elif result_number == 3:
return 'III'
elif result_number == 4:
return 'IV'
elif result_number == 5:
return 'V'
elif result_number == 6:
return 'VI'
elif result_number == 7:
return 'VII'
elif result_number == 8:
return 'VIII'
elif result_number == 9:
return 'IX'
elif result_number == 10:
return 'X'
totalNumeral = get_roman_number(totalNumber)
print('Decimal values {} + {} = {}'.format(firstNumber,secondNumber, totalNumber))
print('Roman Numeral values {} + {} = {}'.format(firstNumeral, secondNumeral, totalNumeral))
when using any values other than I and V i get
Traceback (most recent call last):
File ... line 26, in <module>
totalNumber = firstNumber + secondNumber
TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'''