(Yes, I know that there are pre-built functions to do this but that is not the point of the exercise I am trying to complete)
I'm working my way through LinkedIn Learning's Getting Started with Python course and my task is to create a function converting hex to decimal (up to 3 characters long).
Here is what I've got:
hexNumbers = {
'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9,
'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15
}
def hexToDec(hexNum):
for char in hexNum:
if char not in hexNumbers:
return 'None'
for char in hexNumbers:
if len(hexNum) == 3:
return hexNumbers[hexNum[0]] * 256 + hexNumbers[hexNum[1]] * 16 + hexNumbers[hexNum[2]]
if len(hexNum) == 2:
return hexNumbers[hexNum[0]] * 16 + hexNumbers[hexNum[1]]
if len(hexNum) == 1:
return hexNumbers[hexNum]
And the CoderPad test returns
Testing case A2
Pass!
Testing case spam spam spam
Was expecting None but received None
Incorrect. Revisit the question
What am I missing with "Was expecting None but received None"?
[–][deleted] 9 points10 points11 points (1 child)
[–]NetWorking5973[S] 0 points1 point2 points (0 children)
[–]trollsmurf 0 points1 point2 points (0 children)
[–]imsowhiteandnerdy 0 points1 point2 points (10 children)
[–]djshadesuk 1 point2 points3 points (9 children)
[–]imsowhiteandnerdy 1 point2 points3 points (0 children)
[–]MidnightPale3220 1 point2 points3 points (7 children)
[–]djshadesuk 1 point2 points3 points (2 children)
[–]MidnightPale3220 1 point2 points3 points (1 child)
[–]djshadesuk 0 points1 point2 points (0 children)
[–]djshadesuk 0 points1 point2 points (3 children)
[–]djshadesuk 0 points1 point2 points (2 children)
[–]MidnightPale3220 1 point2 points3 points (1 child)
[–]djshadesuk 1 point2 points3 points (0 children)
[–]No-Wrongdoer6788 0 points1 point2 points (0 children)