In: Computer Science
USING PYTHON
Our gift-wrapping department has ran out of wrapping paper. An order for more wrapping paper needs to be placed. There is a list, generated by the orders department, of the dimensions (length (l), width (w), and height (h)) of each box that needs to be gift wrapped. The list provides the dimensions of each box in inches, l×w×h.
We only need to order exactly as much wrapping paper as is needed and no more.
Fortunately, each package that needs gift wrapping is a cuboid. Which means that you can find the amount of gift-wrapping paper each box requires by finding the total surface area of the cuboid,
surface area=2(lw)+2(wh)+2(hl).
In addition to the surface area of the cuboid, you must also account for loss in the gift-wrapping production process. Each gift-wrapped box requires a loss amount, of wrapping paper, equal to the side of the cuboid with the smallest surface area.
For example
Using the list of boxes that need to be gift-wrapped, write a Python function that outputs the total number of square feet of wrapping paper that needs to be ordered.
https://courses.alrodrig.com/4932/boxes.txt
# Please refer to the attached screenshot of the code and the output in the solution belowL
f = open("boxes.txt", "r") # opens the file boxes.txt
fl =f.readlines() # reads the file line by line
totalWrap = 0 # amount of wrapping paper needed so far
for line in fl:
dimensions = line.split("x") # splits the line at "x" to obtain
length, breadth and height of the cuboid
l = int(dimensions[0]) # Stores value of length
b = int(dimensions[1]) # Stores value of breadth
w = int(dimensions[2]) # Stores value of height
surfaceArea = 2*(l*b + b*w + w*l) # Stores value of total surface
area of the cuboid
smallestsurfArea = min (l*b, b*w, w*l) # Stores value area of
minimum surface area side
totalWrap += surfaceArea + smallestsurfArea # Accumulates the
values to the total wrapping paper needed so far
print(totalWrap) # Prints the value of total wrapping paper that
will be needed = Final Answer