In: Computer Science
On Python
a) Use format() method to print an integer value entered by the user and its cube root with two decimal places.
b) Print the same values as part (a) using format() function with keyword arguments and labels number and cubeRoot as in: format(number=n,cubeRoot=cr)
c) Switch the order of keyword arguments and show that this has no effect on the output.
Answer for the above question:
code:
#Input from user
n=int(input("Enter Number :"))
#Calculating cube Root
cr = pow(n,1/3)
#a Answer
#using format function to print number and cube root
print("Cube Root of {} is {:.2f}".format(n,cr))
#b Answer
#Keyword arguments and labels
print("Cube Root of {number} is {cubeRoot:.2f}".format(number=n,cubeRoot=cr))
#c Answer
#Switcing keyword arguments
print("Cube Root of {number} is {cubeRoot:.2f}".format(cubeRoot=cr,number=n))
OUTPUT:
PS: If you have any doubt please mention in the comment section. I will solve it as soon as possible.