Skip to main content

Assignment 1: Shopping Calculator

Description

You will create a simple shopping calculator. Some items such as milk, eggs, and bread are considered staples are don't include sales tax. All other items are charged a sales tax of 13%. Users will enter the name of an item found at the grocery store, along with the price. If the item name is found in a list of staples, it will not have sales tax applied. The price entered by the user must be numerical, you can use a string function to check this. Once the user has finished entering items and their prices, you program will print a receipt. Each item will be printed along with the price. Your program will print a subtotal on a new line, this is the total cost of all items before tax. Then it will print the total tax for all the eligible items, and finally a grand total: subtotal plus tax.

Here's the full list of foods that can be considered 'staples'. You should put these into a list:

  • milk
  • eggs
  • bread
  • oranges
  • broccoli
  • spaghetti
  • diapers

Sample Output

Please note: you can correctly format Canadian currencies using f-strings. Your pices should have two decimal places at all times. For example:

price = 18.8923  # notice there are too many decimal places
print(f"{price : .02f}") # : .02f specifies float, 2 decimals with zeroes to pad
Shopping Calculator
Please enter an item of food, or press Enter to exit: eggs
Item is: eggs. Please enter the price for this item: 3.49
Please enter an item of food, or press Enter to exit: pork
Item is: pork. Please enter the price for this item: 7.09
Please enter an item of food, or press Enter to exit: candy
Item is: candy. Please enter the price for this item: 1
Please enter an item of food, or press Enter to exit: eggs
Item is: eggs. Please enter the price for this item: 3.9999999
Please enter an item of food, or press Enter to exit: soup
Item is: soup. Please enter the price for this item: um
Error: price must be a number. Example: 1, or 1.99.
Item is: soup. Please enter the price for this item: 2
Please enter an item of food, or press Enter to exit:

RECEIPT
1. eggs $ 3.49
2. pork $ 7.09
3. candy $ 1.00
4. eggs $ 4.00
5. soup $ 2.00
Subtotal: $ 17.58
Tax: $ 1.31
Total: $ 18.89

First Milestone

For your first milestone, you will need to submit the following:

Program Requirements

Program requirements are used as a planning tool to communicate with the client, to identify possible issues and to clarify program behaviour. The objective is not to 'set things in stone', but to create a plan for the next stage of development.

Write out in a Word file the requirements for this program. Use the example in lab 2 to help you do this. Your first milestone does not need to include any Python code at this point. If there are program requirements that you are unclear about, you can also include questions about the functioning of the program here. Think about the datatypes that you will need in order for your program to function. What things need to be saved? Finally, think about what things can go wrong: what types of user input will cause issues, and what types of checks we will need to do to avoid errors. You will graded on how specific you can make your program requirements, and how much thought you've put into your questions. Submit the file to Blackboard as a .docx file.

Second Milestone

For your second milestone, you will need to submit one of the following:

Flow Chart

Flow charts are a tool used for planning. Our field has two challenges: we need to write code that has the correct syntax for our programming language, and we need to break down program requirements into well-defined logic. Often when we are trying to accomplish both of these things simultaneously, we can confused and overwhelmed. The objective of using a flow chart is to tackle the logical challenge first, and then to deal with correct syntax later.

Create a Flow Chart using an appropriate tool. Use the example in lab 3 to help you do this. You may use any application or tool you like to do this, as long as the flow chart follows the conventions taught in the lab. You will be graded on how much thought you've put into solving the program requirements in your flow chart. Again, in the second milestone it's not required that you provide code, only the various checks, loops and conditions that you will be using.

The Final Submission

Name your assignment assign1.py. This should be a working script that I can run on my computer, which will fulfill the program requirements. Here is how your program should look when I am running it:

Additionally, your submission should:

  • contain a docstring at the top, with your name, myseneca ID, and description of the program. For example:
'''
Name: Eric
Myseneca: esmith1
Description: Enter your description of the program here.
'''
  • Your script must not import any modules.
  • Your script must contain at least one function.
  • It's not necessary to justify the items and the prices, like I have done in the example. However, your prices should be correctly displayed, with two fixed decimal numbers for each price.
  • For example: 2.00 instead of 2. Use this guide for help.
  • Your script must use the design patterns taught in class. Code that obviously comes from external sources will be flagged for Academic Integrity violation.
  • You may, however, use any of the built-in methods in Python. For example: .lower(), .count(), etc.
  • You script must contain documentation, including:
    • function-level docstrings
    • in-line comments explaining why you are doing what you're doing in the code.

Ideally, your script should run without errors. However if there are errors, I will award partial marks if you're on the right track.

You will submit assign1.py to Blackboard.

Academic Integrity

A reminder that the college has a Zero Tolerance Policy in regards to academic integrity. In the professional world, an employee who plagiarises is a huge liability for the company. Code falls under intellectual copyright laws: incidents involving stolen have caused litigation and millions of dollars in legal fees for companies. In the professional world, being caught stealing code will result in termination and possibly legal action.

On the other hand, it is expected that junior developers will make mistakes, hit roadblocks, get frustrated, get confused, introduce bugs and need help from a senior developer or mentor. Events are accepted and even celebrated as 'part of the process.' It's always better to ask for help: knowing when you need help is just as important a skill as learning to code.

Even if your code is not working or is incomplete, you will most likely get partial marks for what you have accomplished. Submitting code that is not your own, however, will always get a zero.

What Makes It Plagiarism?

You can absolutely communicate with classmates, and refer to outside sources. When you are discussing problems, use pseudocode or flow charts to explain. Sharing one or two lines of code is acceptable, sharing more than two lines of code is not. Never share your assignment with other students, even if they say it is for reference. You will be charged with an academic integrity violation and receive a zero.

Rubric

ConceptPoints
First Milestone2.5
Second Milestone2.5
Basic Function5
Error Handling2.5
Documentation and Comments2.5
Total15