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.
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.
- Define a function
sqrtthat takes in a single argument
- Inside the function, calculate the square root of
nusing the equation
n ** 0.5and assign the result to the variable
- Prompt the user to enter a number and store the input in the variable
- Call the
sqrtfunction with the argument
nto calculate the square root of the user-specified number.
- Print the result stored in the variable
- Exit the program.
def sqrt(n): x = n ** 0.5 print(x) n = int(input("Enter the number whose square root you need to find: ")) sqrt(n)
Enter the number whose square root you need to find: 25 5.0