In this exercise/project, I am asked to write a function to determine how much it would cost to ship a package of a certain weight using ground shipping. The instructions are as follows:
Write a function for the cost of ground shipping. This function should take one parameter,
weight, and return the
costof shipping a package of that weight.
The instructions include the word “cost” written in code, which makes me believe that I should be returning a variable called “cost” - am I reading this correctly? And, if so, why is it necessary to create a variable within the function to return? It seems like more work to me. Here is the code I wrote for this project, and it worked just fine - even though I didn’t create a variable called “cost”:
def ground_shipping(weight): if weight <= 2: return 20 + (1.5 * weight) elif weight <= 6: return 20 + (3 * weight) elif weight <= 10: return 20 + (4 * weight) else: return 20 + (4.75 * weight)