I need to write a function that converts hex to decimal and I've got an idea of how to do it but I'm stuck at the first bit. So far I am taking the user input and returning it in hex, but this only works if I enter 1 thing at a time. The code is:
def hex(x):
if x == "0":
return 0
elif x == "1":
return 1
elif x == "2":
return 2
elif x == "3":
return 3
elif x == "4":
return 4
elif x == "5":
return 5
elif x == "6":
return 6
elif x == "7":
return 7
elif x == "8":
return 8
elif x == "9":
return 9
elif x == "A":
return 10
elif x == "B":
return 11
elif x == "C":
return 12
elif x == "D":
return 13
elif x == "E":
return 14
elif x == "F":
return 15
print hex(raw_input().upper())
It works if I enter, for example, C then it returns 12, but if I enter 8C then it doesn't work. I can't figure out why this is.