如何打印格式化的项目名称和数量的多个列表



我有一个库存程序,选项1-4有效。目前的问题是选项5。它当前打印括号中的所有项目和数量。

类似:

商品名称:["鸡肉"、"橙子"、"土耳其"]

数量:[12,44,22]


我需要它像一样打印

商品:鸡肉

数量:12


项目:橙子

数量:44


项目:土耳其

数量:22


要复制我的错误类型1,请键入鸡肉,数量12(将项目/数量添加到库存(,键入98(重复更多项目(,然后键入5(当前库存(。

我该如何解决这个问题?

完整代码:

import os

name = []
qty = []
class Foo():
def __init__(self, name, qty):
self.name = name
self.qty = qty
def menuDisplay():
print ('=============================')
print ('= Inventory Management Menu =')
print ('=============================')
print ('(1) Add New Item to Inventory')
print ('(2) Remove Item from Inventory')
print ('(3) Update Inventory')
print ('(4) Search Item in Inventory')
print ('(5) Print Inventory Report')
print ('(99) Quit')
CHOICE = int(input("Enter choice: "))
menuSelection(CHOICE)
def menuSelection(CHOICE):
if CHOICE == 1:
print('Adding Inventory')
print('================')
new_name = input('Enter the name of the item: ')
name.append(new_name)
new_qty = int(input("Enter the quantity of the item: "))
qty.append(new_qty)
CHOICE = int(input('Enter 98 to continue or 99 to exit: '))
if CHOICE == 98:
menuDisplay()
elif CHOICE == 99:
exit()
elif CHOICE == 2:
print('Removing Inventory')
print('==================')
removing = input('Enter the item name to remove from inventory: ')
indexdel = name.index(removing)
name.pop(indexdel)
qty.pop(indexdel)
CHOICE = int(input('Enter 98 to continue or 99 to exit: '))
if CHOICE == 98:
menuDisplay()
elif CHOICE == 99:
exit()
elif CHOICE == 3:
print('Updating Inventory')
print('==================')
item = input('Enter the item to update: ')
update = int(input("Enter the updated quantity. Enter 5 for additional or -5 for less: "))
if update >= 0:
qty[name.index(item)] += update
print("Update made")
CHOICE = int(input('Enter 98 to continue or 99 to exit: '))
if CHOICE == 98:
menuDisplay()
elif CHOICE == 99:
exit()
elif update <= -1:
qty[name.index(item)] += update
print("Update Made")
CHOICE = int(input('Enter 98 to continue or 99 to exit: '))
if CHOICE == 98:
menuDisplay()
elif CHOICE == 99:
exit()
elif CHOICE == 4:
print('Searching Inventory')
print('===================')
search = input('Enter the name of the item: ')
pos = name.index(search) if search in name else -1
if (pos >= 0):
print ('Item:     ', name[pos])
print ('Quantity: ', qty[pos])
print ('----------')
else:
print("Item not in inventory")
CHOICE = int(input('Enter 98 to continue or 99 to exit: '))
if CHOICE == 98:
menuDisplay()
elif CHOICE == 99:
exit()
elif CHOICE == 5:
print('Current Inventory')
print('=================')
print ('Item:     ', name)
print ('Quantity: ', qty)
print ('----------')
CHOICE = int(input('Enter 98 to continue or 99 to exit: '))
if CHOICE == 98:
menuDisplay()
elif CHOICE == 99:
exit()
menuDisplay()
Item = ['Chicken', 'Oranges', 'Turkey']
Quantity = [12, 44, 22]
zipo = list(zip(Item, Quantity))
print("nnn")
for foobar in zipo:
print("Item : ",foobar[0], "nQuantity : ",foobar[1])
print("______________________________________________")

最新更新