Question
Instructions Submit programs that solve the following problems. Your answers must be Python3 code. To get full credit, your programs must be correct and the
Instructions
Submit programs that solve the following problems. Your answers must be Python3 code. To get full credit, your programs must be correct and the code must be neat. Each code file must contain the following header comment (filled out) at the top of the file. Failure to include and fill out the header comment will result in a deduction. The collaboration line should contain the names of anyone in the course with whom you discussed the assignment. You do not need to include the names of staff members.
# NAME:
# ASSIGNMENT:
# COLLABORATION:
Shopping List
In this homework, you will create a shopping list program. In general, it will allow the user to keep track of what they intend to purchase on their next visit to the store. It is a general purpose program so it can accommodate a trip to any kind of store (e.g. grocery, hardware, electronic, etc).
Basic Operation
The program will repeatedly ask the user for a command. The following list of commands form the main menu of the program. The main menu should be reprinted after every command has been executed. The commands are:
Command Description
a Add an item to the list.
d Delete an item from the list.
p Prints the list.
q Quits the shopping list program.
s Swaps the position of two items in the list.
c Calculates and prints the total cost of the shopping list.
IMPORTANT: The shopping list must be able to accommodate any size of list. In other words, dont limit the list to a certain size. The shopping list program must use a Python3 list to store the users shopping information.
Add command: a
When the user types a, the program will ask the user for 3 pieces of information:
Name of the item to purchase.
Quantity of the item to purchase.
Estimate of the cost of the item.
The information entered by the user will be stored in the shopping list.
Delete command: d
When the user types d, the program will ask the user to enter an index. The item at the specified index will be deleted from the shopping list. You may assume the user types an integer for the index, but you may not assume the index is valid for the size of the list. If the index is invalid, the command should be ignored and the program should go back to the main menu. If the index is valid, the program should print the deleted item information to show what was deleted.
Print command: p
Prints all items in the shopping list. You do not need to worry about aligning columns of information. However, you do need to append certain characters to the output. An x should precede the quantity. And a $ should precede the cost. The item number is the items index in the list.
For example:
Item 0: Fish, x3, $5.00
Item 1: Chocolate, x1, $2.00
Item 2: Hammer, x1, $15.00
Item 3: Milk, x2, $4.00
Quit command: q
This command stops the program. However, before the program quits, it should, essentially, repeat a print command automatically so the user can see their final shopping list.
Swap command: s
When the user types s the program will ask the user to enter two indices. Similar to the delete command, both indices must be valid for the size of the list (you can assume they are integers). If they are valid, the program swaps the items at those indices. If either index is not valid, the command is ignored and the program returns to the main menu.
Before a swap of 1 and 3
Item 0: Fish, x3, $5.00
Item 1: Chocolate, x1, $2.00
Item 2: Hammer, x1, $15.00
Item 3: Milk, x2, $4.00
After swapping 1 and 3. Note all info related to the item moves and not just the name.
Item 0: Fish, x3, $5.00
Item 1: Milk, x2, $4.00
Item 2: Hammer, x1, $15.00
Item 3: Chocolate, x1, $2.00
NOTE: The swap command does not print the shopping list. The above example was included to show you what happens to the list during a swap command.
Cost command: c
When the user types c the program goes through the current list and calculates the total cost of all the items the user intends to buy. Note that this includes the quantity. For example, given the following shopping list, the total cost printed would be $40.00.
Item 0: Fish, x3, $5.00
Item 1: Chocolate, x1, $2.00
Item 2: Hammer, x1, $15.00
Item 3: Milk, x2, $4.00
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started