23 lines
584 B
Python
23 lines
584 B
Python
def calculate_area(length, width):
|
|
"""
|
|
Calculate the area of a rectangle.
|
|
|
|
Args:
|
|
length (float): The length of the rectangle
|
|
width (float): The width of the rectangle
|
|
|
|
Returns:
|
|
float: The area of the rectangle
|
|
"""
|
|
if length <= 0 or width <= 0:
|
|
raise ValueError("Length and width must be positive numbers")
|
|
|
|
return length * width
|
|
|
|
# Example usage
|
|
if __name__ == "__main__":
|
|
try:
|
|
area = calculate_area(5, 3)
|
|
print(f"The area is: {area}")
|
|
except ValueError as e:
|
|
print(f"Error: {e}") |