In: Computer Science
CSC 101 Assignment 3
Barista Assistant
Due Date: Friday, October 30 at 11:59 PM
Learning Objectives: Practice combining your knowledge of conditionals, loops, functions, strings, and lists.
What to Submit: Write your program in a Python script named barista.py. Submit this file to the Assignment 3 page on Canvas.
Description
The purpose of this assignment is to write a Python program for a cafe to help baristas create coffee for a customer. Your program will take the customer's order and produce a set of instructions for the barista to make the coffee.
Your application will need to perform the following:
Have the customer enter the type of coffee they want. Options include 'Long Black', 'Flat White', 'Latte', or 'Short Black'.
If the customer does not provide one of the above
options, your program should return the following error message and
ask for input again:
Please try again.
With a correct coffee order that is either a long or
short black, have your program ask the customer if they want milk
on the side. The customer must answer correctly either with 'Y' or
'N' (for yes or no). If they do not answer correctly, have your
program display the following error message and ask for input
again:
Please try again.
For any correct coffee order, have your program ask the
customer if they would like their order to-go. Like the milk
question, this question expects a response of either 'Y' or 'N'. If
they do not answer correctly, have your program display the
following error message and ask for input again:
Please try again.
When checking the customer's request, your program should ignore character case sensitivity. For example, 'Y' and 'y' are both correct, as well as 'Long Black' and 'long BLACK'.
After all the correct answers have been given, have your program print out the customer's coffee request in the following format:
Main Coffee Type
Milk Extra
To-Go Option
Create a function pose_question(prompt,
acceptable_responses) that performs the questioning operation. The
function will check the customer's response based on the
acceptable_responses list. This function is responsible for asking
the question provided in the prompt parameter and checking to see
if the user's response is in the acceptable_responses list.
Upon a successful response, the function will return the user's
input. If not, it will display an error message and continue to
loop.
Hint: Use one of the string methods, .lower() or .upper(), to
ignore character case.
Hint 2: Remember you can use the the in operator to check to see if
an item is part of a list.
For full credit, add extra options to the order, such as flavor syrups, other coffee/espresso drink types, etc. Follow a similar format as the other questions for whatever extra options you decide to add, such as checking for valid responses.
Here is the Python code
def pose_question(prompt, acceptable_responses):
acceptable_responses = [r.lower() for r in acceptable_responses]
while True:
resp = input (prompt).lower()
if resp in acceptable_responses:
return (acceptable_responses.index (resp))
else:
print ("Please try again.")
continue
rsp = ['Long Black', 'Flat White', 'Latte', 'Short Black']
yn = ['Y', 'N']
coffeetype = pose_question ("Which coffee type ['Long Black', 'Flat White', 'Latte', or 'Short Black']: ", rsp)
milk = pose_question ("Do you want milk on the side ['Y', 'N']: ", yn)
togo = pose_question ("Is your order to-go ['Y', 'N']: ", yn)
flavor = pose_question ("Do you want to add a flavor syrup ['Y', 'N']: ", yn)
print ("Main coffee type: ", end = " ")
print (rsp [coffeetype])
print ("Milk extra: ", end = " ")
print (yn [milk])
print ("To-go option: ", end = " ")
print (yn [togo])
print ("Flavor syrup: ", end = " ")
print (yn [flavor])