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

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

    Algorithm:

  1. Define a function named sqrt(n)
  2. Equation, n**0.5 is finding the square root and the result is stored in the variable x.
  3. Take input from the user and store in variable n.
  4.  The function is called to implement the action and print the result.
  5. Exit  

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

Report Error/ Suggestion

Related Posts:

[yuzo_views]











CopyRight © 2019

CopyRight © 2019