Create a program that determine the shipping cost for an order based on the following table:
From
$0.00
$20.00
$50.00
$75.00
To
$19.99
$49.99
$79.99
$1000.00
Price
$2.95
$3.95
$4.95
Free
no
To create a program that determines the shipping cost for an order based on the given table, you can use conditional statements or if-else statements.
Here is an example of how you can implement this program in Python:
```python
def calculate_shipping_cost(order_amount):
if order_amount < 0 or order_amount > 1000.00:
raise ValueError("Invalid order amount")
from_to_prices = {
(0.00, 19.99): 2.95,
(20.00, 49.99): 3.95,
(50.00, 79.99): 4.95,
(75.00, 1000.00): 0.00,
}
shipping_cost = None
for (start, end), price in from_to_prices.items():
if start <= order_amount <= end:
shipping_cost = price
break
return shipping_cost
# Example usage
order_amount = 30.00
shipping_cost = calculate_shipping_cost(order_amount)
print(f"The shipping cost for an order of ${order_amount:.2f} is ${shipping_cost:.2f}")
```
In this example, we define a function called `calculate_shipping_cost` that takes the `order_amount` as an argument. The function uses a dictionary `from_to_prices` to map the ranges of order amounts to their corresponding shipping costs.
We use a for loop to iterate through the dictionary items and check if the `order_amount` falls within the range. If it does, we set the `shipping_cost` variable to the corresponding price and break out of the loop.
Finally, we return the `shipping_cost` value. In the example usage, we calculate the shipping cost for an order amount of $30.00 and print the result.
Note: Make sure to validate the input and handle any edge cases according to your requirements.