Python Legends Please I Don't Understand This Error - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Python Legends Please I Don't Understand This Error (563 Views)
| 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: " .strip()decimal = hexToDecimal(hex.upper()) if decimal == None: print("Incorrect hex number" ![]() 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:Ord only accepts one character. Hmm ![]() |
| Re: Python Legends Please I Don't Understand This Error by Nobody: 10:26am On Jul 02, 2020 |
olamidedivotee:Haaaaa!!! Dem call my name for python matter? JavaScript still dey slap me dem dey involve me for python? Abeg oo |
Encountering This Error In Django: TypeError: 'module' Object Is Not Iterable • If You Don't Understand These Memes Then You Are Not A True Programmer • Who Can Decipher This Error For Me? • 2 • 3 • 4
Can We Team Up To Build An App That Will Compete In The Global Market • Mobile App Developer Needed. • Error Using Grad-cam For Image Classification And Visualization
.strip()