satya

Wednesday, October 7, 2020

Program 21

                                                                              Program 21

Write a function called root that is given a number x and an integer n and returns x1/n. In the function definition, set the default value of n to 2.


def root(x,n=2):

    s=(x**(1/n))

    return(s)


x=int(input("enter the X value:"))

n=int(input("enter the nvalue:"))

res1=root(x)

res2=root(x,n)

print("Root value With Default 'n' value 2 is=",res1)

print("Root value With 'n' value  is=",res2)

OUTPUT:


==== RESTART: D:/old/r19 lab-python/21.py ======

enter the X value:18

enter the nvalue:2

Root value With Default 'n' value 2 is= 4.242640687119285

Root value With 'n' value  is= 4.242640687119285

>>> 

==== RESTART: D:/old/r19 lab-python/21.py =====

enter the X value:12

enter the nvalue:4

Root value With Default 'n' value 2 is= 3.4641016151377544

Root value With 'n' value  is= 1.8612097182041991

>>> 

===RESTART: D:/old/r19 lab-python/21.py =====

enter the X value:16

enter the n value:4

Root value With Default 'n' value 2 is= 4.0

Root value With 'n' value  is= 2.0

>>> 

No comments:

Post a Comment

Program 30

                                                                         Program 30 Write a Python class to implement pow(x, n). class Pow1:...