The Coffee Shop – Price Calculator

Your local coffee shop would like to set up a touchscreen tablet on the counter for the baristas to quickly calculate the cost of the cups of coffee ordered by the customers.

Here are the options available when ordering a coffee:

The new system will need a computer program to let a barista pick up the order details. The barista should be able to specify:

     The type of coffee being ordered: There are 7 options: Espresso, Americano, Latte, Cappuccino, Macchiato, Mocha and Flat White
     The size of their coffee cup. Per default a coffee comes in a medium cup, however a customer may ask of a large or an XL cup.
     Whether they would like to eat in or take their coffee away

Based on the user inputs and the price list provided above, the system should automatically calculate and display the total price of the chosen cup of coffee.

Step 1: Draw a Flowchart for your algorithm

Before attempting to complete the code for this task, grab a piece of paper and draw the flowchart to identify the key inputs, decisions and calculations for your algorithm.

Alternatively, you can also create your flowchart online:
Flowchart Studio

Step 2: Complete the Python Code

Complete the Python code below.

Step 3: Add validation checks

To make your program more robust, add some validation rules on your inputs so that:

     The barista can only enter one of the seven options when entering the type of coffee.
     The barista can only opt for M, L or XL when entering the size of the cup.
     The user can only enter Yes or No when asked whether they would like to opt for the takeaway option.

You can find out more about implementing validation checks in Python using this page (input validation tab).

Step 4: Test Plan

Once your code is complete, test it using the following test plan to make sure all your calculations are correct!

Test # Input Values Expected Output Pass / Fail
#1 Type of Coffee: Espresso
Cup Size: L
Takeaway? Yes
Coffee Cup Price: £4.50
#2 Type of Coffee: Cappuccino
Cup Size: M
Takeaway? No
Coffee Cup Price: £3.00
#3 Type of Coffee: Mocha
Cup Size: XL
Takeaway? Yes
Coffee Cup Price: £6.00
#4 Type of Coffee: Flat White
Cup Size: XL
Takeaway? Yes
Coffee Cup Price: £5.00
#5 Type of Coffee: Breakfast Tea
Cup Size: L
Takeaway? Yes
Invalid option. Please select a type of coffee from the menu.

Ordering Multiple Coffees…

We would like you to improve this system so that when a customer order multiple coffees, the barista can enter all the details for the different coffees being ordered and the system works out the total cost of the order.

These are the three amendments you will have to make to your code:

     Your system should start by asking the barista how many cups of coffees are being ordered.
     Then for each coffee, the barista will enter the details (Type of drink, cup size, takeaway?)
     The system will calculate and output the total price of the order.
unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Did you like this challenge?

Click on a star to rate it!

Average rating 3.9 / 5. Vote count: 40

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!