Question
Module 04, Exercise 3 python. You will write a function that will calculate the cost to ship a package. Define a function named shipcost with
Module 04, Exercise 3
python.
You will write a function that will calculate the cost to ship a package.
Define a function named shipcost with TWO arguments named weight and distance
The function will calculate the cost of the shipment according to the following rules.
Calculating Shipment Cost
Each package costs $1.25 per ounce, plus $.005 per mile of distance between the sender and recipient.
Your function should accept an argument in the form of an int that represents the weight of the package in ounces.
Your function should also accept a second argument in the form of an int that represents the distance in miles.
The cost of a 15 ounce package that travels 2,473 miles would be 31.115. (See the next section for more information.)
Special Note: Rounding
Although you have a little bit of experience with the Python round() function, it does not give us the precision to add trailing zeros.
For example, our calculation above results in 31.115 but we would like it to be 31.12 to represent thirty-one dollars and twelve cents.
We will demonstrate how to deal with currency values soon. For now, do not worry about rounding in your script.
main() Function
You must define a main() function where you will call the shipcost() function and pass the arguments.
Your main() function should also print the returned value (the cost of the shipment) to the terminal.
Hints
- Print only the result of the calculation with NO leading "$". Do not add additional language or annotation
- Do not try to do any rounding
- You do not need to include error handling
Test Your Code
Use the button below to test your code with a value of 10 oz. and 400 miles. The output should be 14.5
TEST CODE - 10 OZ., 400 MILES
Use the button below to test your code with a value of 28 oz. and 1285 miles. The output should be 41.425
TEST CODE - 28 OZ., 1285 MILES
Use the button below to test your code with a value of 6 oz. and 2950 miles. The output should be 22.25
TEST CODE - 6 OZ., 2950 MILES
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started