A python code to convert a number from any base to the base of 10 giving errors . What is wrong with this code? -
import math def baseencode(number, base): ##converting number of base base10 if number == 0: return '0' 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 = baseencode('20',5) print
errors
traceback (most recent call last): file "doubtrob.py", line 19, in <module> = baseencode('20',5) file "doubtrob.py", line 13, in baseencode if number[i]!= [a-z]: nameerror: global name 'a' not defined
isn't int(x, base)
need?
int('20',5) # returns integer 10
Comments
Post a Comment