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


You can understand by Watching video :-



Answer :-

def root(x , n = 2 ) :
    print( x ** (1 / n) )

x = int(input(" Enter a number = "))
n = int(input("Enter nthRoot (For empty Enter 0 )= "))

if n == 0 :
    root( x)

else :
    root(x,n)

Output :-

Enter a number = 4
Enter nthRoot (For empty Enter 0 )= 2
2.0

>>> 

Enter a number = 4
Enter nthRoot (For empty Enter 0 )= 0
2.0

>>> 

Enter a number = 9
Enter nthRoot (For empty Enter 0 )= 3
2.080083823051904

>>> 

Enter a number = 6541
Enter nthRoot (For empty Enter 0 )= 6
4.3245476976058095

>>> 



2 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post