CBSE Class 12 Computer Science
Question 100 of 103
Working with Functions — Question 6
Back to all questions 6
Question 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.
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)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