Stats: 3,174,154 members, 7,890,900 topics. Date: Monday, 15 July 2024 at 11:39 PM |
Nairaland Forum / Science/Technology / Programming / Python Legends Please I Don't Understand This Error (473 Views)
Encountering This Error In Django: TypeError: 'module' Object Is Not Iterable / Who Can Decipher This Error For Me? / I Keep Getting This Error Message "Gradle Project Syn Failed... (2) (3) (4)
Python Legends Please I Don't Understand This Error by olamidedivotee: 3:58pm On Jul 01, 2020 |
crownedrookie brukx def main(): # Prompt the user to enter a hex number hex = input("Enter a hex number: " ![]() 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 1 Like |
Re: Python Legends Please I Don't Understand This Error by osuulola(m): 4:18pm On Jul 01, 2020 |
Maybe you need to parse the input from string to a number? 1 Like 1 Share |
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. 1 Like |
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 |
(1) (Reply)
Mobile App Developer Needed. / Free Python Tutorial For Beginners / Got Data Of Richest People In The World
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 14 |