Today, I will share the code to find the square root of a number in Python. In order to calculate the square root of a number in Python, we will use ** operator.
The ** operator in Python is used to raise the number on the left to the power of the exponent of the right. That is, in the expression 5 ** 3, 5 is being raised to the 3rd power. In mathematics, we often see this expression rendered as 5³, and what is really going on is 5 is being multiplied by itself 3 times.
Python Program to Find the Square Root of A Number
# Python Program to calculate the square root # Note: change this value for a different result #num = 8 # uncomment to take the input from the user num = float(input('Enter a number: ')) num_sqrt = num ** 0.5 print('The square root of %0.3f is %0.3f'%(num ,num_sqrt))
Enter a number: 3
The square root of 3.00000 is 1.732051
Process finished with exit code 0.
Download the code file from GitHub.
Other Python programs: