csci 4 :: programming project 3 (due by midnight on friday, nov 15)

Complete this exercise on your own.

Solve the problem described below by designing, implementing, and testing a Python program.

Email your Python code to the instructor at jboydt@foobt.net before the deadline.

Description:

For this project, you will implement a simulation of a convenience store. Your user will be shown a menu of products (including their prices and how many are in stock) and will be a allowed to select a product (and a quantity) for purchase. The menu will also include an option for the user to "checkout", at which point the program will collect "payment" from the user for the products purchased.

Your program should function as follows:

• main menu display must include the following:
• the total amount currently owed
• a menu containing five (5) items for purchase, with the price and number in stock of each item
• an option to "checkout"
• when your user selects an item for purchase, the program must:
• check to see if there are any of the item left in stock -- if not, display a message and return the user to the main menu
• if there are items in stock, allow the user to specify how many of the item she/he wants to purchase -- this number cannot be more than the number in stock -- allow the user to input zero (0) to cancel the purchase
• on a successful purchase, adjust the total amount the user owes (quantity * price) and adjust the amount of the item in stock
• when your user selects the "checkout" option:
• show the user how much money is "owed" for her/his purchases
• prompt the user to pay for her/his purchases by entering an amount of money
• do not let the user "leave" until she/he has paid enough to cover the amount owed
• show the user her/his amount of "change"
• display a message thanking the user for "shopping" at your store

Document your Python code using this sample as a guide.

Objectives:
• practice arithmetic
• practice using decisions and loops
• use the string format function to format program output
• use lists to manage program data
• use functions to organize program code
• access global variables from within functions
• launch a program through a main function
Requirements:
• technical requirements:
• [50 points] your module must be documented correctly (see the basic_module example)
• [50 points] your program must run without errors
• [50 points] all of your user input handling must be robust
• [50 points] all of your program outputs should be neatly and consistently formatted using the string format when required
• feature requirements:
• [100 points] implement three (3) lists to represent the items in your store -- one list to contain the names of the items, another to contain the prices of the items, and another to contain the quantities of the items in stock
• [100 points] implement a main menu function to (1) display the amount currently owed (will be \$0.00 to start), (2) a table of items including their names, prices, and quantities in stock, and (3) an option to "checkout". For example:
• [50 points] implement a print single item function that accepts as parameters a name, a price, and a quantity and outputs this information using the string format function
• [50 points] implement a print all items function that loops through the items and passes the name, price, and quantity of each item to the print single item function (see requirement above)
• [50 points] implement a buy item function that (1) checks to ensure that the item is available in stock (print an appropriate message if it is not), (2) accepts the user's input about the quantity of the item desired for purchase, and (3) makes necessary adjustments to the total owed by the user and the number of this item remaining in stock
• [50 points] implement a checkout function that ensure that the user pays an adequate amount for her/his purchases; display any change owed
• NOTE: you may implement additional functions as you see fit, but you must have the above functions implemented in your code per the specification
Challenge yourself:

If you have time, enhance your program to include one or more of the following features:

• [25 points] use lists to track what items the user has purchased, and display this information as a "receipt" at the end of the program (after the user checks out). For example:
• [25 points] store item names, prices, and quantities in a text file and write a Python function that will read the file, split each line, and load the data into the lists in your program
Total points for this programming project:

600 points