127k views
2 votes
Write a function with local functions that calculates the volume, side areas, and total surface area of a box based on the lengths of the sides. It will have 3 inputs: the length, width, and height of the box. There will be no outputs since it will simply print the results to the screen.

User Muratiakos
by
5.6k points

1 Answer

7 votes

Answer:

  1. def calcBox(l, w, h):
  2. vol = l*w*h
  3. print("Volume is :" + str(vol))
  4. sideArea1 = h*w
  5. sideArea2 = h*w
  6. sideArea3 = h*l
  7. sideArea4 = h*l
  8. sideArea5 = w*l
  9. sideArea6 = w*l
  10. print("Side Area 1: " + str(sideArea1))
  11. print("Side Area 2: " + str(sideArea2))
  12. print("Side Area 3: " + str(sideArea3))
  13. print("Side Area 4: " + str(sideArea4))
  14. print("Side Area 5: " + str(sideArea5))
  15. print("Side Area 6: " + str(sideArea6))
  16. surfAreas = 2*h*w + 2*h*l + 2*w*l
  17. print("Total surface areas is: " + str(surfAreas))
  18. calcBox(5, 8, 12)

Step-by-step explanation:

Firstly, create a function calcBox that takes three inputs, l, w, and h which denote length, width and height, respectively.

Apply formula to calculate volume and print it out (Line 2-3).

Since there are six side areas of a box, and we define six variables to hold the calculated value of area for one side respectively (Line 5 - 10) and print them out (Line 11-16).

Apply formula to calculate surface areas and print it out (Line 18 - 19)

At last test the function (Line 21).

User Jsmolka
by
6.9k points