human
Convert a number from base A to base B | Function to return ASCII value of a character.
Function to convert a number from given base to decimal number.
Stores the length of the string.
Initialize power of base.
Initialize result.
Decimal equivalent is strr [ len - 1 ] * 1 + strr [ len - 2 ] * base + strr [ len - 3 ] * ( base ^ 2 ) + ....
A digit in input number must be less than number 's base.
Update num.
Update power.
Function to return equivalent character of a given value.
Function to convert a given decimal number to a given base.
Store the result.
Repeatedly divide inputNum by base and take remainder.
Update res.
Update inputNum.
Reverse the result.
Function to convert a given number from a base to another base.
Convert the number from base A to decimal.
Convert the number from decimal to base B.
Prthe result.
Given input.
Function Call"
How can the above be solved in Python?
assistant
#Here is code to convert a number from base A to base B and the other steps required.
 def val ( c ) :
	if ( c >= '0' and c <= '9' ) :
		return ord ( c ) - 48
	else :
		return ord ( c ) - 65 + 10
def toDeci ( strr , base ) :
	lenn = len ( strr )
	power = 1
	num = 0
	for i in range ( lenn - 1 , - 1 , - 1 ) :
		if ( val ( strr [ i ] ) >= base ) :
			print ( " Invalid ▁ Number " )
			return - 1
		num += val ( strr [ i ] ) * power
		power = power * base
	return num
def reVal ( num ) :
	if ( num >= 0 and num <= 9 ) :
		return chr ( num + 48 )
	else :
		return chr ( num - 10 + 65 )
def fromDeci ( base , inputNum ) :
	res = " "
	while ( inputNum > 0 ) :
		res += reVal ( inputNum % base )
		inputNum //= base
	res = res [ : : - 1 ]
	return res
def convertBase ( s , a , b ) :
	num = toDeci ( s , a )
	ans = fromDeci ( b , num )
	print ( ans )
s = "10B "
a = 16
b = 10
convertBase ( s , a , b )