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 rectanglearealength width:
return length width
# Function to compute the surface area of a rectangular solid
def rectangularsolidsurfacearealength width, height:
# Compute the areas of the three pairs of faces
area rectanglearealength width
area rectanglearealength height
area rectangleareawidth height
# Surface area is the sum of the areas of all faces each pair counted twice
return area area area
# Test the functions with different inputs
def testrectangularsolidsurfacearea:
testcases
# Example : length width height
# Example : length width height
# Example : length width heightcube
# Example : length width heightinvalid should be handled
# Example : length width height
for length, width, height in testcases:
try:
surfacearea rectangularsolidsurfacearealength width, height
printfSurface area of rectangular solid with lengthlength widthwidth heightheight is surfacearea
except Exception as e:
printfError computing surface area for dimensions lengthlength widthwidth heightheight: e
# Run the test function
testrectangularsolidsurfacearea
not use testcases
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
