₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,070 members, 8,420,150 topics. Date: Thursday, 04 June 2026 at 12:21 PM

Toggle theme

Python Legends Please I Don't Understand This Error - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingPython Legends Please I Don't Understand This Error (563 Views)

1 Reply (Go Down)

Python Legends Please I Don't Understand This Error by olamidedivotee(op): 3:58pm On Jul 01, 2020
crownedrookie
brukx


def main():

# Prompt the user to enter a hex number

hex = input("Enter a hex number: "wink.strip()


decimal = hexToDecimal(hex.upper())

if decimal == None:

print("Incorrect hex number"wink

else:

print("The decimal value for hex number",

hex, "is", decimal)


def hexToDecimal(hex):

decimalValue = 0

for i in range(len(hex)):

ch = hex[i]

if 'A' <= ch <= 'F' or '0' <= ch <= '9':

decimalValue = decimalValue * 16 + \

hexCharToDecimal(ch)

else:

return None


return decimalValue


def hexToDecimal(ch):

if 'A' <= ch <= 'F':

return 10 + ord(ch) - ord('A')

else:

return ord(ch) - ord(ch)


main() # Call the main function

Re: Python Legends Please I Don't Understand This Error by stanliwise(m): 4:15pm On Jul 01, 2020
Debug the code yourself on each iteration print out the value individually and you may spot were the error is emerging from
Re: Python Legends Please I Don't Understand This Error by Nobody: 4:18pm On Jul 01, 2020
Maybe you need to parse the input from string to a number?
Re: Python Legends Please I Don't Understand This Error by Arg0n(m): 4:40pm On Jul 01, 2020
The ord() function expects just 1 character. You're giving it multiple characters...

Try converting each character in the string one by one.
Re: Python Legends Please I Don't Understand This Error by Nobody: 5:03pm On Jul 01, 2020
Expected a character. That should tell you the problem, the function accepts a single character.
Re: Python Legends Please I Don't Understand This Error by Brukx(m): 9:18pm On Jul 01, 2020
olamidedivotee:
crownedrookie
brukx


def main():

# Prompt the user to enter a hex number

hex = input("Enter a hex number: "wink.strip()


decimal = hexToDecimal(hex.upper())

if decimal == None:

print("Incorrect hex number"wink

else:

print("The decimal value for hex number",

hex, "is", decimal)


def hexToDecimal(hex):

decimalValue = 0

for i in range(len(hex)):

ch = hex[i]

if 'A' <= ch <= 'F' or '0' <= ch <= '9':

decimalValue = decimalValue * 16 + \

hexCharToDecimal(ch)

else:

return None


return decimalValue


def hexToDecimal(ch):

if 'A' <= ch <= 'F':

return 10 + ord(ch) - ord('A')

else:

return ord(ch) - ord(ch)


main() # Call the main function
Ord only accepts one character.
Hmm smiley
Re: Python Legends Please I Don't Understand This Error by Nobody: 10:26am On Jul 02, 2020
olamidedivotee:
crownedrookie
brukx


def main():

# Prompt the user to enter a hex number

hex = input("Enter a hex number: "wink.strip()


decimal = hexToDecimal(hex.upper())

if decimal == None:

print("Incorrect hex number"wink

else:

print("The decimal value for hex number",

hex, "is", decimal)


def hexToDecimal(hex):

decimalValue = 0

for i in range(len(hex)):

ch = hex[i]

if 'A' <= ch <= 'F' or '0' <= ch <= '9':

decimalValue = decimalValue * 16 + \

hexCharToDecimal(ch)

else:

return None


return decimalValue


def hexToDecimal(ch):

if 'A' <= ch <= 'F':

return 10 + ord(ch) - ord('A')

else:

return ord(ch) - ord(ch)


main() # Call the main function
Haaaaa!!! Dem call my name for python matter? JavaScript still dey slap me dem dey involve me for python? Abeg oo
1 Reply

Encountering This Error In Django: TypeError: 'module' Object Is Not IterableIf You Don't Understand These Memes Then You Are Not A True ProgrammerWho Can Decipher This Error For Me?234

Can We Team Up To Build An App That Will Compete In The Global MarketMobile App Developer Needed.Error Using Grad-cam For Image Classification And Visualization