Python 3 Program to Find the Square Root of A Number

In this tutorial, you will learn a simple Python 3 program to find the square root of a number. To understand this program, you should have the knowledge of basic Python programming concepts such as variables and operators.

Also check10 Best Books To Learn Python For Beginners And Experts.

Python 3 Program to Find the Square Root of A Number

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. Therefore, to find the square of a number in Python 3, we will raise a number to the power of 0.5.

Code

# 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))

Run The Program

Output

Enter a number: 3

The square root of 3.00000 is 1.732051

Process finished with exit code 0.

python program to find a square root of a number

 

Download the code file from GitHub.

Related Python 3 Programs:

  1. Python 3 Program To Add Two Matrices.
  2. Python 3 Program to Check Armstrong Number.
  3. Python 3 Program to Find the Sum of Natural Numbers.
  4. Python 3 Program To Find The Factorial Of A Number.
  5. Python 3 Program to Find Largest Among Three Numbers.
  6. Python 3 Program to Check Leap Year.
  7. Python 3 Program To Check If Number Is Positive Or Negative.
  8. Python 3 Program To Convert Celsius To Fahrenheit.
  9. Python 3 Program To Add Two Numbers.
  10. Python 3 Program to Print Hello World.

Scroll to Top