Welcome to Westonci.ca, the place where your questions are answered by a community of knowledgeable contributors. Join our Q&A platform to connect with experts dedicated to providing precise answers to your questions in different areas. Explore comprehensive solutions to your questions from knowledgeable professionals across various fields on our platform.

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)

Sagot :

Answer:

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

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:

[tex]area = 5 * 2 = 10[/tex]

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

[tex]area = 6 * 12 = 72[/tex]