Question: Write a simple program called shopping.py for a store that simulates a shopping cart. Grading This homework will be graded based on effort. Details The

Write a simple program called shopping.py for a store that simulates a shopping cart.
Grading
This homework will be graded based on effort.
Details
The store sells desk, computer, lamp, couch, and notebook. The prices of the items are saved in prices.txt Download prices.txt.(Download the file and put it in the same folder as your Python program.)
Your program should be able to do the following:
Read the file and print the names and unit prices of the items in the shell for the user.
Ask the user what items they want and how many of them they want. The user then enters the names of the items along with the quantity one at a time in the form of "name,quantity" (see examples below).
Save the order to a file calledcart.txt -- Each line is of the form name,unit price,quantity (see examples below).
When they finish, they can enter Done to end the program.
Finally, calculate the total amount the user needs to pay and print the result on the shell.
If for some reason you couldn't see the content of the prices.txt file, here it is (please create an empty prices.txt file in Thonny and copy and paste the content into the file like we did in class):
desk,199.9
computer,1050
lamp,38.5
couch,599.9
notebook,10
Note:
It would help if you save the items with their prices to a nested list while reading the file, so you'll have a nested list [["desk",129.9],["computer",1099],...] to work with.
The user may enter the items in whatever order they prefer. For example, the user may enter couch before desk.
To make things a littler easier, you may assume they will not enter the same item twice. for example, if they want to add 2 desks to the shopping cart, they will enter desk,2 instead of desk,1 twice.
Requirements
You should NOT hardcode the items and their prices. Imagine you are writing a program for a real store so that they can use the program for a long time. If the owner decides to sell new items and add them to the prices.txt Download prices.txtfile, your program should still work.
Handling invalid user input properly (You'll need to use try-except AND if statements.):
If the user enters an item that the store doesn't have, your program should let the user know and keep asking for the next item.If the user input doesn't follow the format name, quantity, your program should let the user know and keep asking for the next item, and your program should NOT add the item to the cart even though the item exists.If the quantity the user enters is not positive, i.e.,(<=0), your program should let the user know and keep asking for the next item, and your program should NOT add the item to the cart even though the item exists.
Same as usual: Organize your code with functions, and no global variables.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!