# SICP 01 — What is Block Structure with Bits on Recursion (in Python)

# usecase

The doc’s aim is to write a procedure for finding a method for finding a square root according to Heron of Alexandria.

# 1. algorithmic definition for finding the square root

# 2. CODE

- composed of 7 functions
`_tryThis`

is a recursive- begins at the bottom with calling the initial guess
`1`

with`return _truncate(_tryThis(1))`

defsqrt(x):

def_average(x, y):

return(x+y)/2def_square(x):

returnx*xdef_abs(x):

ifx<0:

return-x

elifx==0:

return0

else:

returnxdef_improve(guess):

return_average(guess, (x/guess))def_goodEnough(guess):

return_abs(_square(guess)-x)<0.001def_tryThis(guess):

if_goodEnough(guess):

returnguess

else:

return_tryThis(_improve(guess))def_truncate(n, decimals=3):

multiplier=10**decimals

returnint(n*multiplier)/multiplierreturn_truncate(_tryThis(1))

# 3. recursion

- this is a
**recursive definition**that allows to go on until something is true - note the independence of recursion here:
**you don’t need any other looping construct other**than the ability to call the procedure

# 4. block structure

- the structure where procedures contain other procedures within themselves
- it is a package of procedures hidden inside the
`sqrt`

box - users should not care what is within the black box