Computer Science
Write a function to calculate volume of a box with appropriate default values for its parameters. Your function should have the following input parameters :
(a) length of box ;
(b) width of box ;
(c) height of box.
Test it by writing complete program to invoke it.
Python
Python Functions
9 Likes
Answer
def calculate_volume(length = 5, width = 3, height = 2):
return length * width * height
default_volume = calculate_volume()
print("Volume of the box with default values:", default_volume)
v = calculate_volume(10, 7, 15)
print("Volume of the box with default values:", v)
a = calculate_volume(length = 23, height = 6)
print("Volume of the box with default values:", a)
b = calculate_volume(width = 19)
print("Volume of the box with default values:", b)
Output
Volume of the box with default values: 30
Volume of the box with default values: 1050
Volume of the box with default values: 414
Volume of the box with default values: 190
Answered By
3 Likes
Related Questions
What will be the output of the following Python code ?
V = 25 def Fun(Ch): V = 50 print(V, end = Ch) V *= 2 print(V, end = Ch) print(V, end = "*") Fun("!") print(V)
- 25*50!100!25
- 50*100!100!100
- 25*50!100!100
- Error
Write a function that takes amount-in-dollars and dollar-to-rupee conversion price; it then returns the amount converted to rupees. Create the function in both void and non-void forms.
Write a program to have following functions :
(i) a function that takes a number as argument and calculates cube for it. The function does not return a value. If there is no value passed to the function in function call, the function should calculate cube of 2.
(ii) a function that takes two char arguments and returns True if both the arguments are equal otherwise False.
Test both these functions by giving appropriate function call statements.
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.