#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Sun Oct 16 16:33:31 2022 @author: cpresser """ """ Compute Shipping: shipping.py Write a function called shippingCost which takes as an argumaent a package weight in pounds and returns the cost to ship it. The shipping rates are as follows: Weight (lbs) Cost per pound ($) less than 1 3.99 1 to 2 4.99 2 to 4 5.99 4 to 8 6.99 more than 8 7.99 Outside of the function, ask the user for a package weight and print its cost. Sample Run: Weight in pounds? 2.45 The package will cost $14.68 to ship. """ #define the function before we try to use it def shippingCost(w): #assign our cost an initial value cost = 0 if w < 1: cost = 3.99 elif w < 2: # because of the if, this is the same as 1 <= w < 2 cost = 4.99 elif w < 4: # 2 <= w < 4 cost = 5.99 elif w < 8: # 4 <= w < 8 cost = 6.99 else: # w >= 8 cost = 7.99 return cost * w # end of the function #Another equuivalent function def shippingCost2(w): if w < 1: return w * 3.99 elif w < 2: # because of the if, this is the same as 1 <= w < 2 return w * 4.99 elif w < 4: # 2 <= w < 4 return w * 5.99 elif w < 8: # 4 <= w < 8 return w * 6.99 else: # w >= 8 return w * 7.99 # end of the function # This is the main part of the program. # This will run first, calling the functions weight = float(input("Weight in pounds? ")) total_cost = shippingCost(weight) print(f"The package will cost ${total_cost:.2f} to ship.")