KnowledgeBoat Logo

Computer Science

Write a function namely nthRoot( ) that receives two parameters x and n and returns nth root of x i.e., x^(1/n).
The default value of n is 2.

Python

Python Functions

4 Likes

Answer

def nthRoot(x, n = 2):
    return x ** (1/n)

x = int(input("Enter the value of x:"))
n = int(input("Enter the value of n:"))

result = nthRoot(x, n)
print("The", n, "th root of", x, "is:", result)

default_result = nthRoot(x)
print("The square root of", x, "is:", default_result)

Output

Enter the value of x:36
Enter the value of n:6
The 6 th root of 36 is: 1.8171205928321397
The square root of 36 is: 6.0

Answered By

3 Likes


Related Questions