Find square root in python

Written by

Himani Kohli

Square root in Python Program

In this program, we will be designing a code to find the square root of a number given by the user in Python.

The function sqrt is generated in order to find the square root of a number passing the number n as an argument in the function. 

**Note: The exponent operator ** is used to calculate the power of a number. It is written as a ** b, where a is the base and b is the exponent.

Algorithm:

  1. Define a function sqrt that takes in a single argument n.
  2. Inside the function, calculate the square root of n using the equation n ** 0.5 and assign the result to the variable x.
  3. Prompt the user to enter a number and store the input in the variable n.
  4. Call the sqrt function with the argument n to calculate the square root of the user-specified number.
  5. Print the result stored in the variable x.
  6. Exit the program.

Code:

def sqrt(n):
    x = n ** 0.5
    print(x)


n = int(input("Enter the number whose square root you need to find: "))
sqrt(n)

Output:

Enter the number whose square root you need to find: 25

5.0
Find square root in python