A python code to convert a number from any base to the base of 10 giving errors . What is wrong with this code?
- by mekasperasky
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