Python Program to find the square root of a given number

Program

# Python Program to find the square root of a given number
inputNum = float(input('Enter a number: '))
squareRootOfNum = inputNum ** 0.5
print('The square root of %0.3f is %0.3f'%(inputNum ,squareRootOfNum))

This program calculates the square root of a user-provided number using exponentiation.

  1. Take User Input

    • The program asks the user to enter a number (can be an integer or a decimal).
  2. Calculate Square Root

    • The square root is found using the exponentiation operator ** 0.5.
    • In mathematics, the square root of x is the value y such that y * y = x.
  3. Display Output

    • The result is printed with 3 decimal places using '%0.3f' % (inputNum, squareRootOfNum).

Key Takeaways

  • The exponentiation operator ** 0.5 is a simple way to calculate the square root.
  • The program supports floating-point numbers.
  • The output is formatted to display three decimal places.

Output

$ python3 FindSquareRoot.py 
Enter a number: 529
The square root of 529.000 is 23.000