"Shopping Cart" Further Exploration Challenges
Last updated
Was this helpful?
Last updated
Was this helpful?
This document provides optional project challenges for students seeking a greater level of difficulty.
BONUS POINTS: 3-4% (RECOMMENDED)
The store owner likes your work and wants to use your app in all their regional locations. But different municipalities use different sales tax rates. Instead of hard-coding a single sales tax rate, allow each user to configure their own tax rate via an environment variable called TAX_RATE
.
NOTE: Use a ".env" file approach for managing environment variables. Your "README.md" file must contain instructions for how the user can set up their own local ".env" file, including an example of the variable assignment:
NOTE: The ".env" file must be ignored from version control, by using a corresponding entry in the ".gitignore" file.
HINT: use in conjunction with
HINT: you might need to use the
float()
function to convert the environment variable value to a float datatype, so you can perform numeric calculations with it
BONUS POINTS: 3-4%
Add a new product called "Organic Bananas" to the products inventory. Assign it a price of 0.79
, but add another attribute called something like price_per
to indicate the item is priced per "pound". Update all the other product dictionaries to match the new structure, indicating they are priced per "item".
When running the program, if the clerk inputs the identifier of the bananas (or any other item that is priced by pound), the program should ask the clerk to input the number of pounds (e.g. 2.2
), then the program should calculate the price accordingly.
BONUS POINTS: 3-5%
In addition to displaying a receipt at the end of the checkout process, the program should write the receipt information into a new ".txt" file saved in a new "receipts" directory inside the project repository. The clerk's printer-connected computer should be able to actually print a paper receipt from the information contained in this file.
Each text file should be named according to the date and time the checkout process started (e.g. "/receipts/2019-07-04-15-43-13-579531.txt", where the numbers represent the year, month, day, 24-hour-style hour, minute, second, and milliseconds/microseconds, respectively).
NOTE: to prevent clutter, exclude these receipt files from being tracked in version control by creating a new ".gitignore" file in the "receipts" directory, and adding the following contents inside:
BONUS POINTS: 6-8% (RECOMMENDED)
In addition to displaying a receipt at the end of the checkout process, the program should prompt the checkout clerk or the customer to indicate whether the customer would like to receive the receipt by email. And if so, it should prompt the checkout clerk or the customer to input the customer's email address, and then it should send the receipt information to the customer by email. The clerk's network-connected computer should be able to send these emails.
At the very least, the email should display the checkout timestamp and the total price. But ideally it should contain all the receipt information described in the basic requirements.
BONUS POINTS: 3-5%
NOTE: to prevent clutter, exclude the CSV file from being tracked in version control by creating a new ".gitignore" file within the "data" directory, and adding the following contents inside:
BONUS POINTS: 6-8%
BONUS POINTS: 0 (FOR FUN, NO WAY TO VERIFY)
Assemble a handful of real products that have barcodes.
Connect the barcode scanner to your computer's USB port, and practice scanning a few of the items, and record the resulting product identifiers.
Adapt the program's products
variable (or CSV file or Google Sheet, or whatever datastore you're using) to reflect the real products and their identifiers. For example:
NOTE: for real life products, we'll probably want to change the identifier values to strings, in case any contain alphabetic characters or leading zeros (e.g. "LIFE water" identifier above).
After modifying the product list, try re-running the program, using the barcode scanner to scan the real items. It should work!
HINT: consult the notes on for examples of how to write to file in Python
HINT: leverage the email-sending capabilities of , and optionally use to further control the formatting of email contents.
Instead of using a hard-coded products
variable, download or copy the contents of the provided into your project directory in a new subdirectory called "data" (so the path to the CSV file should be "data/products.csv"). Then update your code to read the products
from this CSV file.
HINT: leverage the capabilities of or (recommended) for CSV file management.
Instead of using a hard-coded products
variable or a "products.csv" file as the application's datastore, use this provided instead. Update your code to read the products
from this Google Sheet.
HINT: leverage the capabilities of .
Ask to borrow the professor's barcode scanner during class or office hours, or feel free to .