Question: Write a Python program to help process orders at Amazin.com. The program will take orders for a multiple shopping carts and continue processing until the
Write a Python program to help process orders at Amazin.com. The program will take orders for a multiple shopping carts and continue processing until the user indicates there are no more carts to process. The user will be presented with a short menu showing a list of item categories selected as was done for A4. However, in this assignment the selection of a category will cause a submenu of items to be displayed for user review and possible selection. In addition to what was done for A4, A7 will include the following features:
take orders for multiple shopping carts
present the user with the A4 menu of item categories, but...
...for each category, display a submenu of specific items after that category is selected
the submenu includes a specific named item and its price
collect and validate the item selection number, flag an invalid selection
keep a list of each categorys specific item cost use a list (or tuple) to translate the selected items
menu number into a price (see below for the named items and prices)
accumulate the number of category items and category costs selected the quantity of each selection is
one, but repeated selections may be made by selecting them again from the menu
redisplay the item menu until x is selected, at which point the category menu is selected
redisplay the main category menu and continue processing until c (checkout) is selected from the
category menu
print the checkout summary as was done for A4 the format should display dollars and cents in a format
thats as good as you can make it
ask whether more carts are to be processed
continue until no more carts are desired by the user
print a session summary that includes total number of carts, items, and cost
The category menu will display one of four choices (same as A4):
1 - Books 2 - Electronics 3 - Clothing c - Checkout
Select one of the categories or checkout (1 3 or c):
The following submenu will be displayed for the Books selection when category 1 is selected:
1 - Origin, $19.95 2 Grant, $24.50 3 Prairie Fires, $18.95 x return to category menu
The above is only a display menu for the users benefit. Internally, your program should store the reference information in a list or tuple that consists of the item price in the same order thats displayed on the menu. For the above, the list is:
book_list = [19.95, 22.50, 18.95]
The first list item is the price of Origin and is accessed (used in the program) as book_list[0]. The price for the book Grant, item #2 on the list, can be obtained using book_list[item - 1] since the list index is actually one less than the corresponding menu item. The two other categories, electronics and clothing, have similar submenus and reference lists:
Select an electronics item from the following list, or x to return to the category menu:
1 - HP Laptop, $429.50 2 - EyePhone 10, $790.00 3 - Bose 20 Speakers, $220.00 x return to category menu
Select a clothing item from the following list, or x to return to the category menu:
1 - T-shirt, $9.50 2 - Shoes, $45.00 3 - Pants, $24.00 x return to category menu
The user enters a selection and the program validates it is one of the above (1 through 3 or x). If 1, 2, or 3, the program adds the one of the items and price to the totals for that category. Selecting an item adds one item to the cart (which should be implemented as a list) and one price, so your program represents the cart as a list of lists. The sublists are [
The menu is displayed for more selections until the user selects c (checkout). When checkout is selected the program iterates through the cart (list) and prints a report showing each item in the cart, its price, the total number of items in the cart, and the total price of all items in the cart. For A7 the item price formatting should be as good as you can get it, but wont be perfect. We will soon discuss formatting in class and A8 will require more precise formatting of output.
The program then asks if there are more carts to process and, if yes, repeats the above. If not, the totals for all carts and all item counts and costs is printed.
The final report for all carts should be similar to below.
Total number of carts: 5 Total number of items: 9
Total cost of items:
$140.50
To do this assignment: 1. Decide what the program needs to do and in what order (program logic). For this assignment, the basic
logic flow is (note: the following pseudo-code is approximately correct):
Display the category menu
Prompt for category selection
If {1, 2, 3}, display the item submenu for books, electronics, or clothing
when an item is selected, add the item and its cost to the cart list and redisplay the item menu for possibly more selections in that category
If x is selected, continue with step a. above
If {c}, checkout is selected, display the cart summary.
Prompt user to ask if there are more carts if yes, repeat a-d above, if not print final report
2. Write You will also need to use lists, and possibly tuples and dictionaries.
the Python code. You will need all the control structures weve learned to date (if, while, and for).
You may define your own functions where you think appropriate, although a future assignment will require using them.
Since you are processing multiple carts and multiple items in a single cart there will be a number of while loops controlling the program flow.
Use the Python interpreter mode if needed to be sure single statements work the way you think they do.
When the program is completely written and the syntax errors removed, test the programs logic by running it multiple times.
Consider writing the program in small steps. First write the code to display the submenus, then add logic to
prompt for items and validate the selection, then add logic to add an item to the cart list. Do that for one item type. Once thats working correctly, implement that logic for the other items. Some of that logic can be implemented as a function and reused by the various items rather than hard coding the logic for each.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
