CBSE Class 11 Computer Science Question 47 of 63

Introduction to Python Modules — Question 16

Back to all questions
16
Question

Question 16

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 the complete program to invoke it.

Solution
def calculate_volume(length = 5, width = 3, height = 2):
    return length * width * height

default_volume = calculate_volume()
print("Volume of the box: ", default_volume)

v = calculate_volume(10, 7, 15)
print("Volume of the box: ", v)

a = calculate_volume(length = 23, height = 6)
print("Volume of the box: ", a)

b = calculate_volume(width = 19)
print("Volume of the box: ", b)
Output
Volume of the box:  30
Volume of the box:  1050
Volume of the box:  414
Volume of the box:  190
Answer