human
Write me a code to complement of a number with any base b and the other steps required given the following:
Complement of a number with any base b | Function to find ( b - 1 ) 's complement.
Calculate number of digits in the given number.
Largest digit in the number system with base b.
Largest number in the number system with base b.
return Complement.
Function to find b 's complement.
b ' s ▁ complement ▁ = ▁ ( b - 1 ) ' s complement + 1.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to complement of a number with any base b and the other steps required.
 def prevComplement ( n , b ) :
	maxNum , digits , num = 0 , 0 , n
	while n > 1 :
		digits += 1
		n = n // 10
	maxDigit = b - 1
	while digits :
		maxNum = maxNum * 10 + maxDigit
		digits -= 1
	return maxNum - num
def complement ( n , b ) :
	return prevComplement ( n , b ) + 1
if __name__ == " _ _ main _ _ " :