Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need assistance on this assignment creating a Python script in version 3.6: Make-Up Assignment: Espresso Prices Overview This assignment has several goals: using loops for

Need assistance on this assignment creating a Python script in version 3.6:

"Make-Up" Assignment: Espresso Prices

Overview

This assignment has several goals:

using loops for input validation.

gaining more practice designing and coding with functions.

creating functions with return values.

using conditional logic (if statements).

Please make sure that your solution meets these educational goals.

Important note

This is the "make-up" assignment. This assignment is in addition to the regular assignments in the course. It is provided for people who want some "extra" points for the quarter. You will only receive credit for this assignment if your quarter grade would be less than a 3.0 without it. Also, this assignment will only raise your quarter grade to a 3.0, no higher.

The Specifications

Your brother-in-law, the barista, has heard that you're learning to program. He has asked you to program his POS (point of sale) system to handle his new price list. Fortunately, the POS system he has uses Python as its scripting language. You gladly accept the job.

Drinks

This is a simple espresso stand. It only sells three drinks.

Americano

Espresso

Cappuccino

As you can see, he's not local, otherwise he would have to have a Cafe Latte on the menu as well.

Sizes

The drinks come in two sizes.

Medium, 12 oz.

Large, 16 oz.

Prices

The pricing on Americano is the simplest. Mediums are $0.99 per cup; larges, $1.29 per cup.

The pricing on Espresso is a bit more complicated. $1.75 per cup for medium; $2.25 per cup for large. However, there is a volume discount. The mediums are 3 for $4.25; larges are 3 for $5.50.

The pricing on Cappuccino is similar. $2.29 per cup for medium; $2.59 per cup for large. For cappuccino, the volume discount is 10% off for 4 or more cups.

The User Interface

Placing an order requires three pieces of information.

The type of drink The type of drink can be handled using a single character: A E C

The drink size The size can be handled using a single character as well: M L

The quantity The quantity is an integer.

Based on the order, the POS system shall echo the order and calculate the price. All of the drinks in the order will be the same size and kind. The POS system shall collect the information using three separate questions.

Minimal Version

For the minimal version of the assignment, the system needs to handle only a single order. Here is an example. (In the examples which follow, bold is used to show user input is and the underscore character ( _ ) is used to show that the system is waiting for input.)

Enter number of drinks: 5 Enter drink size (M L): M Enter kind of drink (A E C): E The order is 5 medium espressos. Total bill: $7.75

Note: This is 1*$4.25 + 2*$1.75.

The minimal assignment only needs to accept upper-case responses.

Unrecognized input

If the user inputs a non-numeric value for the number of drinks the program shall not crash. The system shall print out an error message and ask again.

Enter number of drinks: 5R Error in number of drinks. Please try again. Enter number of drinks: _

If the number of drinks is not a positive integer value, the system shall print out an error message and ask again.

Enter number of drinks: 5R Error in number of drinks. Please try again. Enter number of drinks: 5.3 Error in number of drinks. Please try again. Enter number of drinks: _

If the user inputs an unrecognized value for the size or kind of drink, the system shall print out an error message and ask again.

Enter number of drinks: 5 Enter drink size (M L): N Error in drink size. Please try again. Enter drink size (M L): _

The system shall keep asking until acceptable input is given. When the order is complete, the system shall echo the order and print out the total cost.

Enter number of drinks: 5R Error in number of drinks. Please try again. Enter number of drinks: 5.3 Error in number of drinks. Please try again. Enter number of drinks: 5 Enter drink size (M L): N Error in drink size. Please try again. Enter drink size (M L): K Error in drink size. Please try again. Enter drink size (M L): M Enter kind of drink (A E C): C The order is 5 medium cappuccinos. Total bill: $10.31

Note: This is 5*$2.29 - 10%, or $11.45 - $1.145. The print-out shall always show cents, that is, have exactly two places after the decimal point. (Just let the system round the way that it wants.)

Notes for the Minimal Version

The judicious use of functions will simplify writing the assignment. You should have functions to handle input, processing, and output.

For example, a function could handle getting the number of drinks from the user. This would include:

displaying the initial prompt for the number of drinks

getting the input from the user

validating the input (checking to make sure that it is numeric and positive)

displaying the error message and asking again when the input is invalid

returning the validated input value

Each of the three input questions can be handled in this way.

Similarly, handling the calculation of the price can be separated into three different functions, one for each kind of drink. You can have a single function to get the price. It should take the number, size, and kind of drink as three parameters. Looking forward (if you read the extra-credit option), it will be best if this function returns the calculated price. This single price function can call the drink-specific price calculation functions.

And finally, you can create a function that will format and print the output. This is echoing the order and giving the total price.

One of the primary benefits of making all these smaller, separate functions is that you can work on them independently of each other. So, for example, once you have the calculations for espresso drinks working, you don't have to mess with that code (and possibly mess it up) when you go to work on prices for a different kind of drink.

Another benefit of breaking the problem and its solution into smaller chunks, it makes the problem and its solution (the resulting code) more easy to understand and more manageable. In fact, the main for the minimal assignment can just call a few functions. Here it is in pseudo code.

get the number of drinks get the drink size get the kind of drink calculate the price print out the summary

Standard Version

For the standard version of the assignment, the POS system will be modified to handle multiple orders. After completing one order, the system shall ask if there is another order. If the answer is yes, the system prompt again for the new order. The single character 'y' is sufficient. The system shall also keep a running total of the orders filled. After the last order, the total value of the orders for the system shall be displayed.

The order is 5 medium cappuccinos. Total bill: $10.31 Is there another order? Y Enter the number of drinks: _

The blank response, just pressing the return key, shall also be interpreted as 'yes'.

The order is 5 medium cappuccinos. Total bill: $10.31 Is there another order? Enter the number of drinks: _

Any response to this question which is neither 'y' nor empty shall be interpreted as "no" and the system shall end.

The order is 5 medium cappuccinos. Total bill: $10.31 Is there another order? B Total orders for the day: $156.28

Remember that the running total of the orders needs to be kept by the system. The grand total shall be printed with exactly two places after the decimal. (Note: depending on your implementation, the grand total could be off from what you might expect, based on adding the total bill figures for the individual orders. This is due to rounding errors. However, it should not be off by more cents than the number of orders. So, if there were 15 orders, you would expect the grand total to be within 15 cents of sum of the 15 total bill figures given during the run of the program.)

In the standard version of the assignment, the POS system shall accept lower-case input as equivalent to upper-case.

Notes for the Standard Version

The use of functions to get the input and calculate the output should make moving from the minimal version to the standard version much easier. In fact, the change should be limited to main, the driver function that just calls the other "worker" functions.

Challenge Version

For the challenge version of the assignment, the system shall handle simplified order entry. That is, the number of drinks, the size, and the kind of drink can all be entered on the same line. You can assume the order of the elements on the input line are number, size, and kind.

Enter line item: 5 M E This line item: 5 medium espressos, $7.75

However, if any of the inputs are not recognized, entry for the individual piece(s) will be requested.

Enter line item: 5 N E Error in drink size. Please try again. Enter drink size (M L): M This line item: 5 medium espressos, $7.75

The observant student has probably noticed that the POS system now talks about line items. This is the other enhancement for the challenge version: an order can now consist multiple line items. You can think of this as modifying the minimal assignment order into a "line item". A simple yes/no question, like the standard assignment asking for if there is another order, can be used to check if there are more line items.

Enter line item: 5 M E This line item: 5 medium espressos, $7.75 More line items? _

At the end of the order, the system shall print out a summary of all of the line items and the total price.

Enter line item: 5 M E This line item: 5 medium espressos, $7.75 More line items? y Enter line item: 5 M C This line item: 5 medium cappuccinos, $10.31 More line items? n The total order: $18.06 5 medium espressos, $7.75 5 medium cappuccinos, $10.31 Is there another order? _

Note

Like the grand total for the standard version, the total bill may vary from the sum of the multiple "line items" for the bill. As noted before, the resulting total bill value can be off by multiple cents, though not to exceed the number of line items. So, if the complete order has three line items, the total for the order can differ from the project value by up to 3 cents and still be considered passing.

Test Cases

The test cases for the system are pretty straight forward. There are two kinds of test cases: one set for dealing with invalid input, and another for checking the calculations. There are several exams of test cases given in these notes. For the test cases, because we are letting Python handle the rounding, you can consider the test case as passing if the value reported by the script is within a penny of the calculated value.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

1. What does collaboration for articulation look like?

Answered: 1 week ago