Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


COMP1005AB – Fall 2021

Assignment # 2


Submission Guidelines:

Submit a single zip file called A2.zip on Brightspace.

Did you zip it correctly? You must always create the zip files using the built-in, default, archiving program available with your operating system. If we cannot easily open your zip file and extract the python files from them, we cannot grade your assignment. Other file formats, such as rar, 7zip, etc., will not be accepted.

Windows: Highlight (select with ctrl-click) all of your files for submission. Right-click and select “Send to” and then “Compressed (zipped) folder”. Change the name of the new folder “A2.zip”.

MacOS: Highlight (select with shift-click) all of your files for submission in Finder. Right-click on one of the files and select “compress N items…” where N is the number of files you have selected. Rename the “Archive.zip” file “A2.zip”.

Linux: use the zip program.

Did you submit the correct files? You are responsible for ensuring that you have submitted the correct file(s), and the submission is completed successfully. After submitting your A2.zip file to Brightspace, be sure that you download it and then unzip it to make sure that you submitted the correct files. This also checks that your zip file is not corrupted and can be unzipped.

You can submit as many times as you wish and Brightspace will save your latest submission. I would suggest that you submit as soon as you have one question done and keep re-submitting each time you add another problem (or partial problem).

We will not accept excuses like “I accidentally submitted the wrong files” or “I didn’t know that the zip file was corrupt” or “My Internet was down” or “My computer was not working” after the due date.

If you are having issues with submission, contact the instructor before the due date.


Late Policy

The assignment is due on Saturday, October 16th, 2021 by 11:00 PM (Ottawa time). Late submissions are allowed until Sunday, October 17th, 2021, 11:00 PM (Ottawa time), but a penalty will be applied.

Please note that Brightspace will only keep your LAST submission. If you submit on-time and then submit the exact same files after the due date, it will be treated as a LATE assignment.

Here is a summary of the penalties based on the submission time.

  Last submission Day/Time
  Penalty applied
  Saturday, October 16th, 2021 (11:00 PM Ottawa time)
  No penalty
  Sunday, October 17th, 2021 (12:00 PM noon Ottawa time)
  10%
  Sunday, October 17th, 2021 (11:00 PM Ottawa time)
  20%
  Monday, October 18th or later
  100%


Regret Clause

If you think you have committed an academic violation (plagiarism), you have 12 hours after the final allowable submission time (11 AM on Monday, October 18th, for this assignment) to invoke this regret clause.

If you do, you will receive ZERO for the assignment (or portions of it that you invoke the clause for) but will not receive any further sanctions from the Dean’s office. Your assignment will still be used when we are checking for plagiarism, but you would not face any further sanctions if it was decided that you had committed an academic violation.

For example, if you collaborated too closely with another student and this is discovered, you would not be further sanctioned. The other student, if they did not also invoke this clause, may still be further sanctioned by the Dean’s office.

This is not a group project, so collaboration is not allowed on this assignment.


Self Evaluation Quiz Criteria

SE Quiz 2 is a follow up quiz for Assignment-2. Once you submit this assignment, you can take the quiz on Brightspace.

You will be asked some leading questions to help you asses the problem-solving skills that you might have achieved by doing this assignment, such as:

Do you feel more comfortable with programming terminologies?

Did you draw a flow-chart or write a pseudocode to help understand an algorithm?

Did you try to break your problem into smaller sub-problems and solve each sub-problem separately?

Did you use examples to help understand a problem?

Could you explain the problems in your own words to someone else in this class?

Did you find similar or related statements that we've talked about in lecture or tutorial, and did you try to understand how the problems were similar and how they were different?

Did you ask a question on discord that required you to communicate what you understood and what was still confusing?

Did you answer a peer's question on discord?

Do you feel more comfortable using operators (arithmetic, conditional, logical) in Python?

Do you feel more comfortable writing branching control structures in Python?

Did you trace your code/algorithm and make sure it follows correctly and produce correct results?

Did you try to identify the stages of the programming life cycle while you were solving a problem for this assignment?

Do you feel more comfortable with identifying the errors in your code and handling those properly?

For the given assignment, which letter grade would you give yourself (A+, …, F)?

In 2-3 sentences, justify your letter grade selection.

Note: only the last two questions are mandatory for this quiz.

Topics: Conditionals, Looping Control Structures, Functions, Input/Output

In this assignment you will develop an Automated Invoice Generator to assist a business owner to create an e-list, record a transaction, update the inventory, and print an invoice. Throughout the three parts of this assignment, you will build a successively more complex solution to this problem. Please be sure to read through the entire assignment before you begin to design the algorithm and be sure to design your algorithm (pseudocode/flowchart) before you begin to code it. You will only submit the code (py files).


Question 1. Creating an e-List    20 marks

Write a program called a2_q1.py that asks the user (business owner) for their product information and creates an electronic list (e-list) of items. In part-2 of this assignment, customers should be able to use this e-list to purchase multiple products of varying quantities while products are available in stock.

Your program should start by asking the business owner’s name (string) and the name of the company (string). Next, it should ask for three (3) product names (strings), their unit prices (floats), and the total number of products in stock (ints). Finally, it should display the list of items.

Below is a sample run of the program that demonstrates how your output could look (user input is highlighted for emphasis):


Sample output (user input is highlighted for emphasize):

Note: users are always allowed to enter any type of data when asked for input. Your program must always verify the user input. Invalid input should be handled with suitable error messages for each type of invalid input and the prompt should be repeated. To keep things simple, we will consider that when prompted a user can enter either an integer, a string, or a float (i.e., not a combination of letters and digits).

Hint: you may want to use while loops to validate user inputs, i.e., repeat the loop until user enters the correct (type of) input.


Question 2. Printing the Invoice    30 marks

Copy your solution from the question 1 into a new file and name it a2_q2.py. You must not overwrite your previous solution; the marking TA will want to see both files. You will add code to this new file (a2_q2.py) that allows the following functionalities.

The user (customer) can now view the e-list to select items for purchase. They should be able to select the items by entering the corresponding number from the list. Again, invalid selections should be handled with suitable error messages and the list should be repeated (see sample outputs below). Once the customer has selected a product, the program should ask how many of that product the customer would like to buy. Your program must make sure that selected products are available in stock, otherwise it should generate error messages and the menu should be repeated. After every valid selection is made, the current total should be printed, and the stock should be updated on the e-list (see sample outputs below).

When the user completes product selection (i.e., enters 4), it should provide the user with their receipt. The receipt must show (a) the subtotal, (b) tax amount (13% of the subtotal) and (c) the total cost of the purchase. See sample outputs below.


Sample output - 1:

Hint: you may want to use nested loops to repeat the selection process until the user wants to quit the program.

Note: ideally, we should run a2_q1.py only once and save all product information into a database or a file so that a2_q2.py (or some other programs) can read this data and update the inventory as required. Since we have not cover File I/O yet, we must repeat this whole process every time we run a2_q2.py. This gives us a heads-up that more powerful programming concepts are waiting for us in this course.


Problem 3. Discounts for the Lucky Customers    20 marks

Copy your solution from question 2 into a new file and name it a2_p3.py. Again, you must not overwrite your previous solution, the marking TA will want to see both files. You will add code to this new file (a2_p3.py) that allows the following functionalities.

In order to promote sales, the owner decided to give discounts to the customers. The percentage of the discount will depend on how lucky the customer is and that will be decided randomly as follows. Each customer has a 60% chance to be selected as lucky, a 30% chance for being super-lucky, and a 10% chance for being super-duper lucky.

Discounts will be applied as follows.

a lucky customer gets a 10% discount on the subtotal

a super-lucky customer gets a 25% discount on the subtotal

a super-duper lucky customer gets a 50% discount on the subtotal

Hint: you may want to use the random() or the randint() function from Python’s random module (or any other function from this module) to select a lucky/super-lucky/super-duper lucky customer.

Note that all discounts will be applied to the subtotal amount only. That is, another 13% tax will be applied to the discounted subtotal.

So, this is what you must now add to your program. After printing the invoice from question 2, your program must ask the customer whether they want to continue or cancel the transaction. If the user wants to cancel the transaction, your program must print a message, thank the customer, and terminate the current execution of the program. Otherwise, your program must inform (and congratulate the customer) about the discount being applied and a final receipt must be printed.


Sample output – 1 (suppose ‘c’ was selected):


Sample output – 2 (suppose ‘i’ was selected):


Sample output – 3 (suppose ‘i’ was selected):


Some considerations

Your output should be neatly formatted (close to the sample).

You cannot assume that the user enters good input. That is, they may enter strings/numbers/anything, and integer values outside the acceptable range. All these cases must be handled by your program by printing appropriate error messages and repeating the menu until a proper value is entered.

This assignment does not expect you to use any data structures (e.g., lists, dictionaries etc.). You can still use these if you prefer, but you will not receive any bonus marks for that.


Invalid submission and penalty

Submissions with an incorrect name or format will receive a -10 marks penalty, with no exceptions. You are responsible for following the guidelines outlined in this assignment and in the course outline.

Add your name and id number as comments on top of each file. If this info is not present, -10 marks penalty will be applied.

Submissions that crash (i.e., terminate with an error) on execution may receive a mark of zero (0).


A2.zip Submission Recap

You must submit the following python scripts with A2.zip

1. a2_q1.py

2. a2_q2.py

3. a2_q3.py