Delivery Pricing
Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.
As an intern for United Python Shipping Service (UPSS), you've been tasked with modeling a new pricing system:
- Deliveries can be sent at a
'rush'
,'normal'
, or'slow'
speed. The base cost for a'slow'
delivery is $14. The base cost for a'normal'
delivery is $16. And the base cost for a'rush'
delivery is $18. - Each unique item in the package accrues 10% of the base cost of the delivery.
- Beyond the normal increase for items, if the package has
'orange'
or'tomato'
in it, there is an additional fee of $5. (These are the only items you deliver which require costly refrigerated shipment.)
To save you the time of manually computing a package's price each time you speak with a different customer, you want to use Python to quickly give you the answer.
Write a function shipping_cost
that computes the cost of a package delivery under this model, given a list containing items that will go in the package, and the speed of the delivery (as a string). For example:
shipping_cost(['walnuts', 'quinoa', 'walnuts', 'orange', 'orange'], 'slow')
The example above would have cost of 14 + .1*14*3 + 5 = 23.20
for the three unique
items (walnuts, quinoa, and orange) and an extra $5 for refrigeration since oranges are present. Note the $5 extra refrigeration charge is applied at most once,
even if, for example, 'orange'
and 'tomato'
are both in the items list multiple times.
Your code should return the total overall cost of the package delivery, rounded to the nearest cent (two decimal places).
Notes
- You should first solve the problem using pencil and paper for a few sample items lists (it is hard to write a program until you have figured out how to solve the problem!).
- It may be helpful to start by writing a simpler program (for example, one that ignores the $ 5 charge for special items). You can then check for errors in that part before adding new capabilities.
When you are ready, submit your file below for testing:
Next Exercise: Supplier Analytics