human
Check if a number is perfect square without finding square root | Program to find if x is a perfect square ..
Check if mid is perfect square.
Mid is small -> go right to increase mid.
Mid is large -> to left to decrease mid.
Driver code.
Function Call"
How can the above be solved in Python?
assistant
#Here is code to check if a number is perfect square without finding square root and the other steps required.
 def isPerfectSquare ( x ) :
	left = 1
	right = x
	while ( left <= right ) :
		mid = ( left + right ) >> 1
		if ( ( mid * mid ) == x ) :
			return True
		if ( mid * mid < x ) :
			left = mid + 1
		else :
			right = mid - 1
	return False
if __name__ == " _ _ main _ _ " :
	x = 2500
	if ( isPerfectSquare ( x ) ) :
		print ( " Yes " )
	else :
		print ( " No " )