Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You are to write the script ' shopping.py ' . In the data folder you are given three txt files: List.txt , FoodLion.txt and HarrisTeeter.txt
You are to write the script
shopping.py
In the data folder you are given three txt files: List.txt FoodLion.txt and HarrisTeeter.txt List.txt contains a list of the items and quantities of those items that the user wants to buy.
They could be listed as item quantity or quantity item When reading the file, it is your job to differentiate between the two. I have added a comma to separate delimit the item name and quantity.
You are required to read the given data files, and not just copy the data.
Your code should work if we changed the contents of the data files.
HarrisTeeter.txt and FoodLion.txt contain lists of items and their price values. As a shopper you want to find the store that has your item for the cheapest price. If both stores carry your item, buy the quantity
needed from the shop selling the item for the smallest price. If only one shop sells your item, then buy your item from there, regardless of the price. If no shops sell your item, be sure to flag that item as 'Not
Sold'.
Note: These are old prices and have NOT been updated to reflect recent inflation. Plus, they were mostly made up in the first place
You should output the final shopping receipt as follows, containing the store an item was purchased from, the item name, the quantity and the total price after multiplying the item price by its quantity Then
you should output the total. Finally, you should put a list of items that were not found. You may format the output however you'd like as long as it is neat and all items are spaced evenly with columns aligned.
I have attached what I have completed shoppinglist I created to go through the file and create a dictionary with the items wanted and the quantity wantedI created stock to go through the food lion and harris teeter files and create a "stock for them to use later when checking what store has what items but I am not sure how to in checkstore go through the dictionaries to check what store has the item from shoppinglist and print the price with the item. Ideally the receipt would be formatted like theirs, but I am more concerned about checking if the stores have the items. import os
shoplist items: 'quantity':
def shoppinglistlist:
with openlist as file:
lines file.readlines
tempshoplist item : "quant" :
for line in lines:
line.split
if lineisdigit True:
tempshoplist.updateitem : line 'quant' : line
if line is typestr:
tempshoplist.updateitem : line 'quant' : line
if line is typestr:
tempshoplist.updateitem : line 'quant' : line
if lineisdigit True:
tempshoplist.updateitem : line 'quant' : line
else:
printitem not in shopping list"
shoplist.updatetempshoplist
return shoplist
htstock htitems": htprices":
flstock flitems": flprices":
def stockharristeeter, foodlion:
temphtstock items hold": "prices hold":
with openharristeeter as file:
lines file.readlines
for line in lines:
line.split $
temphtstock.updateitemshold': line 'priceshold': line
tempflstock itemshold": "priceshold":
with openfoodlion as file:
lines file.readlines
for line in lines:
line.split $
tempflstock.updateitemshold': line 'priceshold': line
htstock.updatetemphtstock
flstock.updatetempflstock
return htstock, flstock
def checkstoreitemsht pricesht itemsfl pricesfl shoplist:
outofstock
for item in shoplistitems:
if item in itemsht and item in itemsfl:
if itemshtprices itemsfl:
printfHarris Teeter itemshoplistquantityitemsht shoplistquantity
else:
printfFood Lion itemshoplistquantity # need price
if item in itemsht:
printfHarris Teeter itemshoplistitemshtstockhtprices" shoplistquantity
if item in itemsfl:
# append receipt
printfFood Lion itemshoplistquantitypricesfl
else:
printItem is out of stock"
outofstock.appenditem
if namemain:
list ospath.joindata "List.txt
foodlion ospath.joindata "FoodLion.txt
harristeeter ospath.joindata "HarrisTeeter.txt
dictlist shoppinglistlist
dictht stockharristeeter
dictfl shoppinglistfoodlion
printfStore Item Quantity
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