Question: # Write a function that computes the area of a rectangle. # Then, write a second function that calls this function three times to compute

# Write a function that computes the area of a rectangle.
# Then, write a second function that calls this function three times to compute the surface area of a rectangular solid.
# Write code to test this function with different inputs.
# Function to compute the area of a rectangle
def rectangle_area(length, width):
return length * width
# Function to compute the surface area of a rectangular solid
def rectangular_solid_surface_area(length, width, height):
# Compute the areas of the three pairs of faces
area1= rectangle_area(length, width)
area2= rectangle_area(length, height)
area3= rectangle_area(width, height)
# Surface area is the sum of the areas of all faces (each pair counted twice)
return 2*(area1+ area2+ area3)
# Test the functions with different inputs
def test_rectangular_solid_surface_area():
test_cases =[
(2,3,4), # Example 1: length=2, width=3, height=4
(5,6,7), # Example 2: length=5, width=6, height=7
(1,1,1), # Example 3: length=1, width=1, height=1(cube)
(0,5,7), # Example 4: length=0, width=5, height=7(invalid, should be handled)
(4,5,6), # Example 5: length=4, width=5, height=6
]
for length, width, height in test_cases:
try:
surface_area = rectangular_solid_surface_area(length, width, height)
print(f"Surface area of rectangular solid with length={length}, width={width}, height={height} is {surface_area}")
except Exception as e:
print(f"Error computing surface area for dimensions (length={length}, width={width}, height={height}): {e}")
# Run the test function
test_rectangular_solid_surface_area()
not use test_cases

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!