88.3k views
1 vote
The Maui coffee shop sells coffee at $10.50 a pound plus the cost of shipping. Each order ships for $0.86 per pound + $1.50 fixed cost for overhead. Write a program that calculates the cost of an order. Get input from the user, calculate the cost, and display the output. using functions.

User F P
by
3.4k points

1 Answer

3 votes

Answer:

  1. def calculateOrder():
  2. pound = float(input("Enter number of pound ordered: "))
  3. COST_PER_POUND = 10.5
  4. SHIP_PER_POUND = 0.86
  5. OVERHEAD = 1.5
  6. shipping = SHIP_PER_POUND * pound
  7. total_cost = pound * COST_PER_POUND + shipping + OVERHEAD
  8. print("Total cost: $" + str(total_cost))
  9. calculateOrder()

Step-by-step explanation:

The solution code is written in Python 3.

Firstly we declare a function calculateOrder (Line 1). Next we use input function to prompt user to enter the number of pound of coffee they wish to order (Line 2). Create three constant variables to hold the value of cost per pound, shipping fee per pound and the overhead charge (Line 3-5). We first calculate the shipping charge (Line 6) and then adding the shipping charge along with the cost for coffee ordered and the overhead charge (Line 7). Lastly, print the total cost (Line 8).

We test the function (Line 10).

User Fan Ouyang
by
3.3k points