Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The objective of this problem is to show that you understand how to write a prog

ID: 3866633 • Letter: T

Question

The objective of this problem is to show that you understand how to write a program that can read CSV files and process the data.

File cart.csv contains shopping cart type data from golfsmith.com representing the gifts you have purchased for your dad for this past Fathers Day. Good for you. You have been very generous!

The first item in each row of the file is the part number, the second the quantity, the third the price and the fourth the description.

Your program will read the file line by line and compute the total cost of all of the items in the list. You will then display a message that looks like this, assuming the cost of each item adds up to 168.42:

Here's what your output should look like:

The shopping cart can be found here: cart.csv. Right click on the link and save the file to the folder where you have your Python files.

Explanation / Answer

Python code: Total_price = 0
with open('cart.csv', 'r') as file:
for line in file:
  tmp = line.split()
  part_no = int(tmp[0])
  quantity = int(tmp[1])
  price = int(tmp[2])
  print "Price for part number: ", part_no, " = ", quantity*price
  Total_price = Total_price + quantity*price
print "Total_price = ", Total_price Sample cart.csv: 1 5 50 description1
2 4 50 description2
3 2 50 description3
4 3 50 description4 Sample Output: Price for part number: 1 = 250
Price for part number: 2 = 200
Price for part number: 3 = 100
Price for part number: 4 = 150
Total_price = 700
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote