20.0k views
3 votes
I Previous

C Reset
2/40 (ID: 34700)
E AA
Examine the following code:
Mark For Review
def area (width, height)
area = width * height
return area
boxlarea = area (5,2)
box2area = area (6)
What needs to change in order for the height in the area function to be 12 if a height is not specified when calling the function?
0 0 0 0
Add a height variable setting height =12 inside the function
Change the box2area line to box 2area = area (6,12)
Add a height variable setting height =12 before the function is declared
Change the def to def area (width, height = 12)

User USB
by
3.3k points

1 Answer

2 votes

Answer:

D. Change the def to def area (width, height = 12)

Step-by-step explanation:

Required

Update the function to set height to 12 when height is not passed

To do this, we simply update the def function to:

def area (width, height = 12)

So:

In boxlarea = area (5,2), the area will be calculated as:


area = 5 * 2 = 10

In box2area = area (6), where height is not passed, the area will be calculated as:


area = 6 * 12 = 72

User Michael Ambrus
by
3.8k points