I was required to write a Python program for Sal's Shipping.
The program:
- Asks the user for the weight of their package;
- Tells them which method of shipping is cheapest; and
- Tells them how much it will cost to ship their package using Sal’s Shippers.
Sal’s Shippers has several different options for a customer to ship their package:
- Ground Shipping, which is a small flat charge plus a rate based on the weight of your package.
- Ground Shipping Premium, which is a much higher flat charge, but you aren’t charged for weight.
- Drone Shipping (new), which has no flat charge, but the rate based on weight is triple the rate of ground shipping.
Weight of Package | Price per Pound | Flat Charge |
---|---|---|
2 lb or less | $1.50 | $20.00 |
Over 2 lb but less than or equal to 6 lb | $3.00 | $20.00 |
Over 6 lb but less than or equal to 10 lb | $4.00 | $20.00 |
Over 10 lb | $4.75 | $20.00 |
Flat charge: $125.00
Weight of Package | Price per Pound | Flat Charge |
---|---|---|
2 lb or less | $4.50 | $0.00 |
Over 2 lb but less than or equal to 6 lb | $9.00 | $0.00 |
Over 6 lb but less than or equal to 10 lb | $12.00 | $0.00 |
Over 10 lb | $14.25 | $0.00 |
The file here contains the Python Program to help Sal's Shipping customers select the best option for their shipping needs.
I used if/elif/else statements to define the pricing structure set out above, per this image:
I used the code to answer the question:
- What is the cheapest method of shipping a 4.8 pound package and how much would it cost?
To do so I defined the weight variable as per the below:
The output from running the code is:
As such, the cheapest option for the customer is Ground Shipping for a price of $34.40.
I used the code to answer the question:
- What is the cheapest method of shipping a 41.5 pound package and how much would it cost?
To do so I defined the weight variable as per the below:
The output from running the code is:
As such, the cheapest option for the customer is Ground Shipping Premium for a price of $125.