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
To create a program that determines the shipping cost for an order based on the given table, you can use a combination of conditional statements and comparisons. Here's a step-by-step guide to creating such a program in Python:
1. Define the table as a list of tuples, where each tuple represents a range of prices and the corresponding shipping cost. For example:
```
table = [
(0.00, 19.99, 2.95),
(20.00, 49.99, 3.95),
(50.00, 79.99, 4.95),
(75.00, 1000.00, 0.00) # Free shipping
]
```
2. Get the order value from the user. This could be done through user input or as a parameter to a function. For example:
```
order_value = float(input("Enter the order value: "))
```
3. Iterate over the table and check if the order value falls within any of the price ranges. Once a match is found, return the corresponding shipping cost. If no match is found, you can either return an error message or a default shipping cost. Here's an example implementation:
```
def calculate_shipping_cost(order_value):
for price_range in table:
min_price, max_price, shipping_cost = price_range
if min_price <= order_value <= max_price:
return shipping_cost
return "Shipping cost not found" # or return a default value
shipping_cost = calculate_shipping_cost(order_value)
print("Shipping cost:", shipping_cost)
```
4. Test your program with different order values to verify that it returns the correct shipping costs.
That's it! You now have a program that determines the shipping cost for an order based on the given table. Remember to adjust the table values and code logic as needed for your specific use case.