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