human
Give me a code to bakhshali Approximation for computing square roots and the other steps required given the following:
Bakhshali Approximation for computing square roots | This Python3 program gives result approximated to 5 decimal places ..
This will be the nearest perfect square to s.
This is the sqrt of pSq.
Find the nearest perfect square to s.
calculate d.
calculate P.
calculate A.
calculate sqrt ( S ) ..
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to bakhshali Approximation for computing square roots and the other steps required.
 def sqroot ( s ) :
	pSq = 0 ;
	N = 0 ;
	for i in range ( int ( s ) , 0 , - 1 ) :
		for j in range ( 1 , i ) :
			if ( j * j == i ) :
				pSq = i ;
				N = j ;
				break ;
		if ( pSq > 0 ) :
			break ;
d = s - pSq ;
P = d / ( 2.0 * N ) ;
A = N + P ;
	sqrt_of_s = A - ( ( P * P ) / ( 2.0 * A ) ) ;
	return sqrt_of_s ;
num = 9.2345 ;
sqroot_of_num = sqroot ( num ) ;
print ( " Square ▁ root ▁ of ▁ " , num , " = " , round ( ( sqroot_of_num * 100000.0 ) / 100000.0 , 5 ) ) ;