A function provides a better way

The better way is to create a separate program module that has the ability to calculate the square root.

Then make that module available for use as a helper to your main program each time your main program needs to calculate a square root.