Lesson 13 Programming Assignment
Crumbl wants to give a discount to their best customers. But, they must buy 3 or more cookies and 3 or more additional items to qualify. Also, the 20% discount does not apply to the cookies.
Write a program that helps them accomplish this.
Objectives
- Formulate a working solution to a business problem that incorporates lists, loops, functions, conditionals, and formatting.
- Construct a flowchart that demonstrates the logic of an algorithm.
Directions
- Develop your algorithm before writing any code. Create a flowchart to represent your logic.
- diagrams.net is a free and easy tool you can use to create flowcharts.
- I created an instructional video outlining how to create and submit flowcharts.
-
Design a program that prompts a cashier to enter a price, then either a
y
for a cookie or an
for a non-cookie item. The cashier will signal he is finished by pressing the<enter>
key instead of a price. Otherwise, the price and boolean cookie status (True, False) should be saved in their respective lists. Call the function described below to calculate the discount, then display the discount to the console. - Create the function
discount(prices, is_cookie)
. The parameters are lists created by the cashier’s entries. For the 0th item,prices[0
is the price before any discount, andis_cookie[0]
isTrue
if that item is a cookie. The function should return the total discount. The function does not print anything to the console.- If the customer bought 3 or more cookies, and 3 or more non-cookie items, the customer receives a 20% discount on the non-cookie items.
- Format the user prompt and output exactly as shown in the example below:
Enter price, or <enter> to quit: 5 Is this a cookie? (y/n only): n Enter price, or <enter> to quit: 5 Is this a cookie? (y/n only): n Enter price, or <enter> to quit: 5 Is this a cookie? (y/n only): n Enter price, or <enter> to quit: 6 Is this a cookie? (y/n only): y Enter price, or <enter> to quit: 7 Is this a cookie? (y/n only): y Enter price, or <enter> to quit: 3 Is this a cookie? (y/n only): y Enter price, or <enter> to quit: 5 Is this a cookie? (y/n only): y Enter price, or <enter> to quit: Discount: $4.20
-
Test your program by running it several times with different inputs. Verify your algorithm is correct by checking the program output against your own calculations.
-
Add the required docstring to the top of your program:
''' Assignment: Lesson 13 Programming Assignment Author: Jane Doe Due Date: MM/DD/YYYY CS-1030; Professor Bianca Ruiz Description: <Description of program goes here> '''
Submission
-
Complete and submit your program as outlined in this instructional video
-
Add your flowchart to the flowchart directory as outlined in this instructional video