как получить идентификатор товара и количество, купленное/возвращенное пользователем, для обновления списка запасов, где get_item_id и write_updated_inventory являются разными функциями

#python #function #spyder #inventory

#python #function #spyder #inventory

Вопрос:

Мы создаем программу, которая хранит запасы и позволяет клиентам приобретать/возвращать товары. У нас есть инвентарь, элемент транзакции и основные модули с вызываемыми классами и функциями.

модуль инвентаризации:

 class Inventory():  def __init__(self, new_id, new_name, new_stock, new_price):  self.__id = new_id  self.__name = new_name  self.__stock = new_stock  self.__price = new_price    def get_id(self):  return self.__id  def get_name(self):  return self.__name   def get_stock(self):  return self.__stock   def get_price(self, price):  return self.__price  def restock(self, new_stock):  if new_stock lt; 0:  return False  else:  return True   def purchase(self, purch_qty):  # new_stock = True  if purch_qty lt;= self.__stock:  self.__stock -= purch_qty  return True  else:  return False   def __str__(self):  string= "ID: "   self.__id   "Item: "   self.__name   "Price: "   self.__price   "Stock: "   self.__stock  return string    

Модуль транзакций

 import inventory class TransactionItem(inventory.Inventory):  def __init__(self, new_id, new_name, new_stock, new_price):  super().__init__(new_id, new_name, new_stock, new_price)   #accessors and mutators    def get_id(self):  return self.__id  def set_id(self, new_id):  self.__id = new_id  def get_name(self):  return self.__name  def set_name(self, new_name):  self.__name = new_name  def get_qty(self):  return self.__stock  def set_qty(self, new_stock):  self.__stock = new_stock  def get_price(self):  return self.__price  def set_price(self, new_price):  self.__price = new_price   #not accessors or mutators, they manipulate attributes of inventory class    def calc_cost(self):  cost = self.__price * self.__stock  return cost  def __str__(self, newInventoryList):  string2 = super().__str__()   "Cost: "   self.__cost  return string2  

Main module

 def main():     #create inventory class instances here to store each item as an instances in new list    def process_inventory():  file = open("Inventory.txt", "r")    lines = file.readlines()    inventoryList = []    newInventoryList = []        for line in lines:   line = line.rstrip('n')  inventoryList.append(line)          begIndex= 0  endIndex = 3      for index in range(len(inventoryList)//4):  itemList = (inventoryList[begIndex:endIndex 1])  newInventoryList.append(itemList)    begIndex  = 4  endIndex  = 4      return newInventoryList  process_inventory()     def print_inventory(newInventoryList):  d = newInventoryList    print("{:lt;8} {:lt;25} {:lt;10} {:lt;5}".format('ID','Name','Stock', 'Price'))    for v in d:  id, name, stock, price = v  print("{:lt;8} {:lt;25} {:lt;10} {:lt;7}".format( id, name, stock, price))  print('Enter 0 when finished.')  print_inventory(process_inventory())    #create another menu from inventory list    def get_item_id():  return_qty = 0  purch_qty = 0  purch_id = int(input('Please input the item id you wish to purchse/return: '))  if purch_id == 0:  pass  elif purch_id == type(int) and purch_id == id:  cust_qty = int(input('Please enter the desired quantity (negaive quantity for return): '))  if cust_qty lt; 0:  cust_qty = return_qty  elif cust_qty gt; 0:  cust_qty = purch_qty  while purch_id != type(int) or purch_id != id:  print("Input was invalid.")  print(purch_id = int(input('Please input the item id you wish to purchse/return: ')))      #add in final invoice unless customer didn't do anything, just say thank you  get_item_id()  #validate item id, 0 means quit program    def write_updated_inventory():  pass  #create output file caled UpdatedInventory.txt    def print_invoice():  inventory.Inventory(str)    print_invoice()  #literally just print an invoice, not same as menu fro inventory  #inlude sales tax    #print default message      main()  '''  

We’re having a lot of trouble figuring this out since we’re beginners and are hoping for some guidance, at least in the main module so that it correctly validates the item id from the user. Right now, all of the entries get an «Input is invalid» message. Also, everything in our files is properly indented, it’s just not here for some reason, it won’t let me indent while editing.