This function to calculate the area of a rectangle is not very readable. Can you refactor it, and then call the function to calculate the area with base of 5 and height of 6? Tip: a function that calculates the area of a rectangle should probably be called rectangle_area, and if it's receiving base and height, that's what the parameters should be called.

Respuesta :

Answer:

Here is the refactored function:

def rectangle_area(base, height):

   area = base * height

   return area    

print("The area is ", rectangle_area(5,6))

Step-by-step explanation:

The above program has a function rectangle_area that takes two variables base and height as parameters. The function then computes the area of rectangle by multiplying the values of base and height. The result of the multiplication is assigned to the variable area. Then the function returns the resultant area.

print("The area is ", rectangle_area(5,6)) statement calls rectangle_area() method by passing values of base and height i.e. 5 and 6 to compute the area. The output of this program is:

The area is 30

Note that the use of rectangle_area function name describes what the function does i.e. it computes the area of rectangle. By naming the parameters as base and height that clearly depicts that in order to compute rectangle are we need the base and height of rectangle. So this makes the code readable.

Ver imagen mahamnasir