Python3-将用户响应添加到列表中,而不是过度编写的现有数据



我正在尝试编写一个基本的商店前脚本,该脚本循环直到客户对问题说不。每次都有项目编号的输入时,我都在尝试存储它,然后最终能够将这些数字与项目名称和价格匹配(虽然还不是还不是)...

我现在只是试图将其添加到空列表中&quot&quot&quot'而不是添加最后一个条目并过度编写了先前的数字。

店主

products = ['Notebook', 'Atari', 'TrapperKeeper', 'Jeans', 'Insects', 
'Harbormaster', 'Lobotomy', 'PunkRock', 'HorseFeathers', 'Pants', 
'Plants', 'Salami']
prices = ['$4.99', '$99.99', '$89.99', '$3.99', '$2.99', '$299.99', 
'$19.99', '$3.99', '$4.99', '$2.99', '$119.99', '$1.99']
SKUs = [1, 2, 3, 4, 5, 6, 7, 8 ,9, 10, 11, 12]
item_nums = ()
quantity = []
response = ''
#MORE VARIABLES AND FUNCTIONS WILL GO HERE
print("Jay's House of Rip-Offsnn")
titles = ['Item Number', 'Item Name', 'Price']
data = [titles] + list(zip(SKUs, products, prices))
for i, d in enumerate(data):
    line = '|'.join(str(x).ljust(16) for x in d)
    print(line)
    if i == 0:
        print('-' * len(line))
response = str(input("Order products [Y / N]?: "))
while response != 'N':
    item_nums = input("Enter an item number: ")
    SKUs.append(item_nums)
    response = str(input("Order products [Y / N]?: "))
    if response == 'N':
        break
print("Here is the list of items you ordered: ",item_nums[0])

我不确定为什么要附加到SKU,您需要一个新列表来跟踪订单号。

orders = []
while str(input("Order products [Y / N]?: ")) != 'N':
    item_nums = input("Enter an item number: ")
    orders.append(item_nums)
print("Here is the list of items you ordered: ", orders)

相关内容

  • 没有找到相关文章

最新更新