python - checking whether representation of number in a given base is valid -



python - checking whether representation of number in a given base is valid -

i have written code checks whether number correctly represented in given base. invalid cases gives false true ones says string index out of range.

def check(n,a,i=0): if int(n[i])>=a : homecoming false else: homecoming check(n,a,i+1) n = str(input('enter no:')) =int(input('enter base:')) print(check(n,a,i=0))

as @ooga pointed out, need check when i larger length of number, can create like:

def check(n,a,i=0): if len(n) <= i: homecoming true if int(n[i])>=a : homecoming false else: homecoming check(n,a,i+1) n = str(input('enter no:')) = int(input('enter base:')) print(check(n,a,i=0))

python numbers base representation

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -