Skip to content

Instantly share code, notes, and snippets.

@les-peters
Last active December 7, 2021 22:50
Show Gist options
  • Select an option

  • Save les-peters/b2d42364fb739e37cbb0d583ace0673e to your computer and use it in GitHub Desktop.

Select an option

Save les-peters/b2d42364fb739e37cbb0d583ace0673e to your computer and use it in GitHub Desktop.
Wrapping Gifts
question = """
You have to order wrapping paper for presents. Given the length, width,
and height of the boxes you need to wrap, return the number of square feet
(or whatever units you want) of wrapping paper you need to order.
Extra credit: allow for other shapes of presents and their dimensions!
Example:
$ wrap(2, 3, 4)
$ 52 square feet
"""
import math
"""
Unlike painting a room, wrapping a gift usually involves a small amount
of overlap between the edges; in this example, that is set to 1 inch.
"""
overlap_inch = 1
def inches_to_ft_in(decimal_inches):
feet = math.floor(decimal_inches / 12)
inches = decimal_inches - (feet * 12)
return(str(feet)
+ " ft, "
+ str(inches)
+ " in" )
def wrap(dimensions):
dimensions.sort()
h_in = dimensions.pop(0) * 12
w_in = dimensions.pop(0) * 12
l_in = dimensions.pop(0) * 12
l_paper = ((2 * (h_in + w_in)) + overlap_inch)
w_paper = ((l_in + h_in) + overlap_inch)
paper_area = l_paper * w_paper
return (str(round(paper_area / 144,2))
+ ' square feet: '
+ inches_to_ft_in(l_paper)
+ " by "
+ inches_to_ft_in(w_paper))
print(wrap([2,3,4]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment