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 'q' to quit.
Using Classes is MANDATORY.
Using Pandas is Prohibited.
ManufacturerList.txt
1167234,Apple,phone
2390112,Dell,laptop
9034210,Dell,tower
7346234,Lenovo,laptop,Y
3001265,Samsung,phone
2347800,Apple,laptop
1009453,Lenovo,tower
PriceList.txt
3001265,1200
2347800,999
2390112,799
1009453,599
1167234,534
9034210,345
7346234,239
ServiceDatesList.txt
9034210,5/27/2020
2390112,7/2/2020
2347800,7/3/2020
7346234,9/1/2020
1009453,10/1/2020
1167234,2/1/2021
3001265,12/1/2023
from datetime import datetime, date
class Item:
def __init__(self, item_id, manufacturer, item_type, is_damaged=False, price=None, service_date=None):
self.item_id = item_id
self.manufacturer = manufacturer
self.item_type = item_type
self.is_damaged = is_damaged
self.price = price
self.service_date = service_date
def is_valid(self):
today = date.today()
return not self.is_damaged and (self.service_date is None or self.service_date >= today)
class Inventory:
def __init__(self, manufacturer_file, price_file, service_date_file):
self.items ={}
self.load_manufacturer_list(manufacturer_file)
self.load_price_list(price_file)
self.load_service_date_list(service_date_file)
def load_manufacturer_list(self, file_path):
with open(file_path, 'r') as file:
for line in file:
item_id, manufacturer, item_type, *is_damaged = line.strip().split(',')
is_damaged = len(is_damaged)>0
self.items[item_id]= Item(item_id, manufacturer, item_type, is_damaged)
def load_price_list(self, file_path):
with open(file_path, 'r') as file:
for line in file:
item_id, price = line.strip().split(',')
if item_id in self.items:
self.items[item_id].price = float(price)
def load_service_date_list(self, file_path):
with open(file_path, 'r') as file:
for line in file:
item_id, service_date = line.strip().split(',')
if item_id in self.items:
self.items[item_id].service_date = datetime.strptime(service_date, '%m/%d/%Y').date()
def query_item(self, manufacturer, item_type):
valid_items =[item for item in self.items.values() if item.manufacturer == manufacturer and item.item_type == item_type and item.is_valid()]
if not valid_items:
print("No such item in inventory")
return
valid_items.sort(key=lambda item: item.price, reverse=True)
best_item = valid_items[0]
print(f"Your item is: {best_item.item_id},{best_item.manufacturer},{best_item.item_type}, ${best_item.price:.2f}")
other_manufacturers =[item for item in valid_items[1:] if item.manufacturer != best_item.manufacturer]
if other_manufacturers:
other_manufacturers.sort(key=lambda item: abs(item.price - best_item.price))
closest_item = other_manufacturers[0]
print(f"You may, also, consider: {closest_item.item_id},{closest_item.manufacturer},{closest_item.item_type}, ${closest_item.price:.2f}")
def run_inventory_query():
inventory = Inventory('ManufacturerList.txt', 'PriceList.txt', 'ServiceDatesList.txt')
while True:
user_input = input("Enter manufacturer and item type (e.g., Apple computer) or 'q' to quit: ").strip().lower()
if user_input =='q':
break
parts = user_input.split()
if len(parts)2:
print("Invalid input. Please enter manufacturer and item type.")
continue
manufacturer = parts[0]
item_type =''.join(parts[1:])
inventory.query_item(manufacturer, item_type)
if __name__=="__main__":
run_inventory_query()
PLEASE DO NOT USE PANDA OR LAMBDA My code can

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!