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: ** is exponent operator. a**b (a raised to the power b).
- Define a function named sqrt(n)
- Equation, n**0.5 is finding the square root and the result is stored in the variable x.
- Take input from the user and store in variable n.
- The function is called to implement the action and print the result.
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