~1 min read • Updated Oct 12, 2025
Program Overview
This Python program receives the dimensions of a box—length, width, and height—as input parameters.
It uses a method to calculate and display the volume of the box.
The formula for volume is:
Volume = Length × Width × Height
This exercise helps users become familiar with defining and using methods with parameters.
Python Code:
def calculate_volume(length: float, width: float, height: float) -> float:
return length * width * height
# Read dimensions from user
length = float(input("Enter box length: "))
width = float(input("Enter box width: "))
height = float(input("Enter box height: "))
volume = calculate_volume(length, width, height)
print(f"Box volume: {volume:.2f} cubic units")
Sample Output (input: length = 2, width = 3, height = 4):
Box volume: 24.00 cubic units
Step-by-Step Explanation:
- The user enters the box’s length, width, and height
- These values are passed to a method that calculates the volume
- The result is displayed with two decimal places
Written & researched by Dr. Shahin Siami