A python code to convert a number from any base to the base of 10 giving errors . What is wrong with this code?
Posted
by
mekasperasky
on Stack Overflow
See other posts from Stack Overflow
or by mekasperasky
Published on 2011-02-09T15:09:52Z
Indexed on
2011/02/09
15:25 UTC
Read the original article
Hit count: 233
python
import math
def baseencode(number, base):
##Converting a number of any base to base10
if number == 0:
return '0'
for i in range(0,len(number)):
if number[i]!= [A-Z]:
num = num + number[i]*pow(i,base)
else :
num = num + (9 + ord(number[i])) *pow(i,base)
return num
a = baseencode('20',5)
print a
Errors I get are
Traceback (most recent call last):
File "doubtrob.py", line 19, in <module>
a = baseencode('20',5)
File "doubtrob.py", line 13, in baseencode
if number[i]!= [A-Z]:
NameError: global name 'A' is not defined
© Stack Overflow or respective owner