我有一个由读取TXT文件的2个列表。1列表包含项目的代码,其他列表包含相应的价格。我正在尝试让用户输入代码,然后搜索该代码的代码列表,并使用此代码打印相应的价格:
while code != "9999":
code = input("Enter 4-digit item code [or 9999 to stop]: ")
if code in priceNumList:
y = priceList.index(code)
print("Item found: ", priceList[y])
elif code not in priceNumList:
print("Item not found.")
每当我运行此并输入列表中的代码时,我会收到以下错误:
Traceback (most recent call last):
File "C:/Users/Jeste/Documents/Python Projects/Homework/wakemart.py", line
36, in <module>
y = priceList.index(code)
ValueError: '####' is not in list
我确定我要输入的价格代码与列表中的元素完全匹配,但是该程序告诉我它不在那里。我在做什么错?
没关系我想知道它!问题是" y = pricelist.index(code("应该是" y = priceNumlist.index(code(",这就是我列出两个列表的原因!:p