Assignment 2: Restaurant Chatbot
You have been hired by Amazing Restaurants of Canada to create a chatbot that allows their customers to order items in their restaurant. They want the program to display a menu, allow the customer (the user) to type in what they would like to order (and how many), and finally print a receipt to the screen.
You can pick what items the restaurant sells, but they must sell drinks and food:
- Drinks
- At least 4 different drinks.
- All drinks cost $1.50, except for one or two drinks must be free ($0) (possibly water?).
- Food
- At least 6 different foods.
- All food costs $2.15, except for two or three must be free (possibly fruit/veggies?).
When ordering food or drinks:
- Ask the user up to 10 times to enter an item to order.
- Number your prompts 1, 2, ...
- The user types in the name of the food or drink to order.
- If they enter the name of a food or drink you don't sell, show an error message.
- If the user just presses enters without typing anything (after stripping characters it's an empty string) then stop asking for items and go on with printing the receipt.
(Hint: You can break out of a loop by callingbreak
; see details below.)
- The user types in how many of that food or drink they want to order.
- They can only order between 1 and 99 (inclusive) of any item at a time. If they order less than 1, display a message and change the quantity to 1; if they order more than 99, display a message and change the quantity to 99.
- A user can only order 99 of an item at a time, but there's nothing stopping them from buying the item more than once. For example, ordering 99 oranges 10 times is fine.
Print the receipt for items ordered:
- If the user did not purchase anything, display a message than nothing was purchased.
- Print the receipt showing the items that were ordered.
- Display the quantity ordered.
- Display the name of the item.
- Display the cost for that quantity of this item.
- If the user ordered the same item 3 times, then it's OK (expected) to have that item listed 3 times on the receipt.
- At the bottom, print the sub-total, tax (5%), and the grand total that includes tax.
- List how many rows of items appear on the receipt.
Technical Requirements
- You must store your drinks and food options in lists (or dictionaries) and use the
in
keyword in your Boolean expressions. - When you print the menu, you must use at least one for loop.
- Your solution must use the accumulation pattern in the price calculation. (Create a variable initialized to zero, and then add to it when needed).
- Your solution must be robust to capitalization, spaces, additional periods and exclamation marks at the front or back of an input, for all inputs.
- Other than the robustness requirement above, your solution may otherwise assume that the user will type a menu item exactly. For example, your system does not need to be robust to "I'll have a salad, please".
- You can also assume that the user will use a number (e.g. 2, not "two") when responding to questions regarding quantity.
- Your output should look as good as the output below. Some specifics you must do include:
- Menu prices must all line up.
(Hint: Use something likef"{item_name:10} - ...."
) - You must use either the
.format()
method, or the formatted string literal (f-string like f"...") to output the final price with exactly two digits after the decimal point. - Line up the output nicely for quantities up to 99, and prices up to $999.99. If the price exceeds this it's OK if the columns don't line up perfectly.
- Menu prices must all line up.
- You may change some things in your program, such as:
- You can change the items that you have for sale (but must be drinks and food). The general costs for food and drinks must match what is listed in this assignment, and you must have some free items as mentioned above.
- Your prompt could be on the same line as the question, or on the next line.
- You can phrase your questions and responses differently than shown above.
- If you use an AI tool (like Copilot or Chat GPT) to generate any of your code, you must mention that in your code as a comment.
- Remember the quiz will test you on your ability to do the things required to complete this assignment.
- If you copy more than one or two lines of code from another source, you must mention it in a comment for those lines.
Remember to design your algorithm in English first, then translate it to Python code. Test as you go!
Readability Guidelines
- Ensure that there is a comment at the top of the file with
- Description of the file
- Your name & date
- All import statements should be placed at the top of the file, immediately after the header
- Modules should only be included once per file
- Well-named variables (describes their purpose)
- Each line of code should be less than 100 characters
- Group your code into smaller sections or paragraphs, and give each a descriptive comment.
Suggestions
- In order for your program to first ask the user about what they want to order, and then later print the receipt, you'll need to store each item and quantity the user orders so you have that info later. It is suggested you store that info in a list of strings which are ready to be printed as the receipt later.
- Create a variable of type list before the user starts ordering anything. Make it an empty list, similar to:
da_badly_named_list = []
- Each time the user orders something, append the string that you want to appear on the receipt later.
- When printing the receipt, you will already have all the information needed as a full string, so you can just iterate through this list of items ordered and print out each string.
- Create a variable of type list before the user starts ordering anything. Make it an empty list, similar to:
- Use the accumulator pattern to track the cost of food and drink purchased.
- Each time an item is ordered, add to the accumulator the total cost for that item in that quantity.
- It is awkward to keep handling different prices for different items. Note that items either cost the standard cost for food or drink, or they are free. Create a list of free items to easily allow you to handle their $0 cost.
- You must not write your code to explicitly check for individual foods. Add the foods/drinks to different lists and use
in
to check if a user's item is a food or is a drink. break
allows you to leave a loop early. For example, this code will print the numbers 0-5:# Print 0-5 for i in range(100): if i == 6: break print(i)
- Use this to handle when the user just presses enter (their input == "").
Getting Started
- Read through the assignment and especially the output below.
- Plan out the basics of the algorithm you want to use to handle ordering.
- Try out the algorithm yourself to see if it works.
- Think how to print the receipt: What do you need to know? Where in your program will you know those things?
- Start coding:
- Break down your algorithm into smaller pieces to code.
- Write a little code, test a little code.
- Try starting with printing the menu, then moving on to placing an order and printing the receipt.
- Use the debugger if your program is not doing what you expected.
Submission
Submit your file directly to CourSys (don't ZIP it)
Submission Notes
- All submissions will be compared for unexplainable similarities. We expect submissions will be somewhat similar for this assignment but do your own original work; we are checking!
- Do not email/give your code to another student. Do not accept code from another student. Do not post your code online.
Troubleshooting Submission Problem
Here are some things to look at if you have challenges submitting:
- When submitting your source code to CourSys, it will enforce that the files have the correct names. Ensure your file names are exactly as expected.
- Ensure your files have a .py file extension.
- Ensure your files do not have anything extra in their name, such as "chatbot.py.source". Your computer may hide file extensions by default, so search the web for "Show file extensions in ___" (fill in the blank with your OS) for directions.
- After submitting, you can verify if any files were submitted by viewing the assignment page on CourSys. It should allow you to view/download your submission.
Marking Notes
- Code that does not run (i.e., crashes or produces an error stopping the program) then it will get a mark of 0.
- To ensure your code works try to finish early so you can get help from TAs if needed! It is better to submit code that works perfectly but doesn't contain all the features, than one that has all the features (potentially) but crashes.
- Each line of your code should NOT exceed 100 characters. This is to help you develop a habit of good code formatting.
- In most cases you can break long code into separate steps, and some components that span multiple lines.
- You could also use intermediate variables to store parts of long messages to be printed (more situations will be seen as the course advances).
- If you are using offline IDEs like VS Code or IDLE, you can look at the bottom of the editor which often tells you how many characters you have typed in a line (as COL's).
- If you are using Replit, first go to Settings on the left panel and set "Wrapping" to "none". Then use this sentence as a guide:
# This line has exactly 100 characters (including the period), use it to keep each line under limit.
Sample Output
Output 1: Ordering 5 times
DRINKS
coke zero $1.50
sprite $1.50
coffee $1.50
water Free!
FOOD
apple Free!
orange Free!
pepperoni pizza $2.15
hamburger $2.15
salad $2.15
[1] What would you like to order? sprite
How many would you like? 2
[2] What would you like to order? water
How many would you like? 10
[3] What would you like to order? hamburger
How many would you like? 3
[4] What would you like to order? water
How many would you like? 2
[5] What would you like to order?
RECEIPT
2x sprite $ 3.00
10x water $ 0.00
3x hamburger $ 6.45
2x water $ 0.00
----------------------------------
Sub total: $ 9.45
Tax: $ 0.47
Total $ 9.92
Receipt lists 4 items.
Note that on the 5th prompt, the user just pressed ENTER
, causing the program to stop asking for more items.
Output 2: Ordering Nothing (just hit enter)
DRINKS
coke zero $1.50
sprite $1.50
coffee $1.50
water Free!
FOOD
apple Free!
orange Free!
pepperoni pizza $2.15
hamburger $2.15
salad $2.15
[1] What would you like to order?
RECEIPT
Nothing purchased.
Output 3: Error Handling
DRINKS
coke zero $1.50
sprite $1.50
coffee $1.50
water Free!
FOOD
apple Free!
orange Free!
pepperoni pizza $2.15
hamburger $2.15
salad $2.15
[1] What would you like to order? Hot dog
I'm sorry, I don't think we sell that.
Please enter the name of something you'd like to order.
[2] What would you like to order? A Sprite, please.
I'm sorry, I don't think we sell that.
Please enter the name of something you'd like to order.
[3] What would you like to order? .! SPRITE !!!!!
How many would you like? -10
I assume you meant 1!
[4] What would you like to order? ...Water...
How many would you like? 100
I assume you meant 99!
[5] What would you like to order? apple!
How many would you like? !!!.... 99 . ! ! .
[6] What would you like to order?
RECEIPT
1x sprite $ 1.50
99x water $ 0.00
99x apple $ 0.00
----------------------------------
Sub total: $ 1.50
Tax: $ 0.08
Total $ 1.57
Receipt lists 3 items.
Output 4: Ordering Many Items
DRINKS
coke zero $1.50
sprite $1.50
coffee $1.50
water Free!
FOOD
apple Free!
orange Free!
pepperoni pizza $2.15
hamburger $2.15
salad $2.15
[1] What would you like to order? water
How many would you like? 10
[2] What would you like to order? apple
How many would you like? 20
[3] What would you like to order? orange
How many would you like? 30
[4] What would you like to order? coke zero
How many would you like? 40
[5] What would you like to order? sprite
How many would you like? 50
[6] What would you like to order? coffee
How many would you like? 60
[7] What would you like to order? pepperoni pizza
How many would you like? 70
[8] What would you like to order? hamburger
How many would you like? 80
[9] What would you like to order? salad
How many would you like? 90
[10] What would you like to order? pepperoni pizza
How many would you like? 99
RECEIPT
10x water $ 0.00
20x apple $ 0.00
30x orange $ 0.00
40x coke zero $ 60.00
50x sprite $ 75.00
60x coffee $ 90.00
70x pepperoni pizza $150.50
80x hamburger $172.00
90x salad $193.50
99x pepperoni pizza $212.85
----------------------------------
Sub total: $953.85
Tax: $ 47.69
Total $1001.54
Receipt lists 10 items.
Note when the subtotal or total at the bottom is >$999.99 it won't have enough room so it will messed up the columns. That's OK.