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
Write a function that receives two numbers and generates a random number from that range. Using this function, the main program should be able to print three numbers randomly.
Write a function that receives two string arguments and checks whether they are same-length strings (returns True in this case otherwise False).
Write a function that takes a number n and then returns a randomly generated number having exactly n digits (not starting with zero) e.g., if n is 2 then function can randomly return a number 10-99 but 07, 02 etc. are not valid two digit numbers.
Write a function that takes two numbers and returns the number that has minimum one's digit.
[For example, if numbers passed are 491 and 278, then the function will return 491 because it has got minimum one's digit out of two given numbers (491's 1 is < 278's 8)].