I have a piece of code from an exam paper that I'm doing for extra help.
The code I need help with:
def Denary(Hex):
Result = ''
ErrorFound = False
DenaryEquivalent = ''
EmptyInput=""
for ThisHexDigit in Hex:
if ThisHexDigit in ['1','2','3','4','5','6','7','8','9','0','A','B','C','D','E','F']:
if ThisHexDigit == '0': DenaryEquivalent = '0'
elif ThisHexDigit == '1': DenaryEquivalent = '1'
elif ThisHexDigit == '2': DenaryEquivalent = '2'
elif ThisHexDigit == '3': DenaryEquivalent = '3'
elif ThisHexDigit == '4': DenaryEquivalent = '4'
elif ThisHexDigit == '5': DenaryEquivalent = '5'
elif ThisHexDigit == '6': DenaryEquivalent = '6'
elif ThisHexDigit == '7': DenaryEquivalent = '7'
elif ThisHexDigit == '8': DenaryEquivalent = '8'
elif ThisHexDigit == '9': DenaryEquivalent = '9'
elif ThisHexDigit == 'A': DenaryEquivalent = '10'
elif ThisHexDigit == 'B': DenaryEquivalent = '11'
elif ThisHexDigit == 'C': DenaryEquivalent = '12'
elif ThisHexDigit == 'D': DenaryEquivalent = '13'
elif ThisHexDigit == 'E': DenaryEquivalent = '14'
elif ThisHexDigit == 'F': DenaryEquivalent = '15'
elif ThisHexDigit == '10': DenaryEquivalent = '16'
elif Hex==EmptyInput:
print('Empty input, try again.')
Result = Result + DenaryEquivalent
else:
ErrorFound == True
print('You have made a mistake')
def HexToDenary():
Hexadecimal = input('Enter a hexadecimal number: ')
Converted = Denary(Hexadecimal)
print (Converted)
When run, there are no errors and the program works (this is only part of it). What I want to know is how I'd add the result instead of it appearing as a binary answer. For example if I enter 'BB', I get '1111' instead of 187. It should be easy but I can't figure it out.
And I know this is an over complicated piece of code but it is what was given.