Insert all the valid combinations to a dictionary
of tuple
s, and if the combination is not there, return 0:
def convert_what(numeral_sys_1, numeral_sys_2):
numeral_dict = {
("Hexadecimal", "Decimal" ) : 1,
("Hexadecimal", "Binary" ) : 2,
("Decimal", "Hexadecimal") : 4,
("Decimal", "Binary" ) : 6,
("Binary", "Hexadecimal") : 5,
("Binary", "Decimal" ) : 3
}
return numeral_dict.get((numeral_sys_1, numeral_sys_2), 0)
If you are planning to use the function in a loop, it may be a better idea to define the dictionary outside the function, so it wouldn’t be recreated on every call to the function.