Question: PLEASE DO NOT USE PANDA OR LAMBDA My code can read the txt files, but doesn't return the correct information when I type it in
PLEASE DO NOT USE PANDA OR LAMBDA
My code can read the txt files, but doesn't return the correct information when I type it in the prompt. Please help
Interactive Inventory Query Capability
Query the user of an item by asking for manufacturer and item type.
Print a message No such item in inventory" if either the manufacturer
or the item type is not in the inventory, more that one of either type is
submitted or the combination is not in the inventory. Ignore any other
words, so "nice Apple computer" is treated the same as "Apple
computer".
Print "Your item is: with the item ID manufacturer name, item type, and
price on one line. Do not provide items that are past their service date or
damaged. If there is more than one item, provide the most expensive
item.
Also, print "You may, also, consider:" and print information about the
same item type from another manufacturer that closes in price to the
output item. Only print this if the same item from another manufacturer is
in the inventory and is not damaged nor past its service date.
After output for one query, query the user again. Allow to quit.
Using Classes is MANDATORY.
Using Pandas is Prohibited.
ManufacturerList.txt
Apple,phone
Dell,laptop
Dell,tower
Lenovo,laptop,Y
Samsung,phone
Apple,laptop
Lenovo,tower
PriceList.txt
ServiceDatesList.txt
from datetime import datetime, date
class Item:
def initself itemid manufacturer, itemtype, isdamagedFalse, priceNone, servicedateNone:
self.itemid itemid
self.manufacturer manufacturer
self.itemtype itemtype
self.isdamaged isdamaged
self.price price
self.servicedate servicedate
def isvalidself:
today date.today
return not self.isdamaged and selfservicedate is None or self.servicedate today
class Inventory:
def initself manufacturerfile, pricefile, servicedatefile:
self.items
self.loadmanufacturerlistmanufacturerfile
self.loadpricelistpricefile
self.loadservicedatelistservicedatefile
def loadmanufacturerlistself filepath:
with openfilepath, r as file:
for line in file:
itemid manufacturer, itemtype, isdamaged line.stripsplit
isdamaged lenisdamaged
self.itemsitemid Itemitemid manufacturer, itemtype, isdamaged
def loadpricelistself filepath:
with openfilepath, r as file:
for line in file:
itemid price line.stripsplit
if itemid in self.items:
self.itemsitemidprice floatprice
def loadservicedatelistself filepath:
with openfilepath, r as file:
for line in file:
itemid servicedate line.stripsplit
if itemid in self.items:
self.itemsitemidservicedate datetime.strptimeservicedate, mdYdate
def queryitemself manufacturer, itemtype:
validitems item for item in self.items.values if item.manufacturer manufacturer and item.itemtype itemtype and item.isvalid
if not validitems:
printNo such item in inventory"
return
validitems.sortkeylambda item: item.price, reverseTrue
bestitem validitems
printfYour item is: bestitem.itemidbestitem.manufacturerbestitem.itemtype $bestitem.price:f
othermanufacturers item for item in validitems: if item.manufacturer bestitem.manufacturer
if othermanufacturers:
othermanufacturers.sortkeylambda item: absitemprice bestitem.price
closestitem othermanufacturers
printfYou may, also, consider: closestitem.itemidclosestitem.manufacturerclosestitem.itemtype $closestitem.price:f
def runinventoryquery:
inventory InventoryManufacturerListtxt 'PriceList.txt 'ServiceDatesList.txt
while True:
userinput inputEnter manufacturer and item type eg Apple computer or q to quit: striplower
if userinput q:
break
parts userinput.split
if lenparts:
printInvalid input. Please enter manufacturer and item type."
continue
manufacturer parts
itemtype joinparts:
inventory.queryitemmanufacturer itemtype
if namemain:
runinventoryquery
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
