Hello everyone, welcome back! Here we learn about a python program which finds the square root of a given number. We find the square-root of a number using exponential operations.
Here I calculate the square-root by finding the power of the number with 0.5, as you all know that square-root of a number is equal to its power by half. So now I use this way to calculate the result.
One can also find the square-root of a number using a built-in function called sqrt()
, Look at my other post here which shows the same.
[embedyt] https://www.youtube.com/watch?v=Cvxoc1H2qAI[/embedyt]
You can watch this video on youtube here
Square Root – Code Visualization
Task :
To find the square-root of a given number
Approach :
- Read input number for which the square root is to be calculated using
input()
orraw_input()
. - Use exponential operation ** to that number with 0.5
- The obtained result of the above operation is required square-root.
- Print the result.
Program :
num = float(input('Enter a number: ')) sqrt = num ** 0.5 print('The square root of %0.3f is %0.3f' % (num, sqrt))
Output :
SquareRoot of a given number – programminginpython.com
SquareRoot of a given number – programminginpython.com
SquareRoot of a given number – programminginpython.com