human
Check if a number N can be expressed in base B | Function to check if a number N can be expressed in base B.
Check if n is greater than 0.
Initialize a boolean variable.
Check if digit is 0 or 1.
Subtract the appropriate power of B from it and increment higher digit.
Driver code.
Given number N and base B.
Function call"
How can the above be solved in Python?

What is a code to check if a number N can be expressed in base B and the other steps required?
assistant
#Here is code to check if a number N can be expressed in base B and the other steps required.
 def check ( n , w ) :
	a = [ 0 for i in range ( 105 ) ] ;
	p = 0
	while ( n > 0 ) :
		a [ p ] = n % w
		p += 1
		n //= w
	flag = True
	for i in range ( 101 ) :
		if ( a [ i ] == 0 or a [ i ] == 1 ) :
			continue
		elif ( a [ i ] == w or a [ i ] == w - 1 ) :
			a [ i + 1 ] += 1
		else :
			flag = False
	return flag
if __name__ == " _ _ main _ _ " :
	B = 3
	N = 7
	if ( check ( N , B ) ) :
		print ( " Yes " )
	else :
		print ( " No " )