如果我输入品牌“ Nike”或类似的名称,我试图获取代码以提供诸如物品价格之类的信息。但是,我将错误代码作为标题。请任何帮助将不胜感激
clothing_brands = [
["544", "Jordan", "Shoes", 200],
["681", "Stussy", "Sweatshirt", 50],
["481", "Obey", "T-Shirt", 30],
["339", "North Face", "Jacket", 80],
["250", "Levis", "Jeans", 40],
["091", "Nike", "Socks", 10],
]
def findClothing(brand):
found = False
for brand in clothing_brands:
if clothing_brands in brand[1]:
found = True
break
if found:
return brand
else:
return None
def printBrand(brand):
print ("\n~~~~Thrift Shop Brands:~~~~")
print ("Item Number:", brand[0])
print ("Brand Name:", brand[1])
print ("Clothing Type:", brand[2])
print ("Price:", brand[3])
if __name__ == "__main__":
print ("\n~~~Welcome to Macklemore's clothing Thrift Shop~~~~")
print ("1) Add a brand you would like to see us carry")
print ("2) What is the brand's clothing type?")
print ("3) What is the price of a particular brand?")
print ("4) What is a brand's information?")
print ("5) Print everything we have in stock")
print ("0) Exit")
while True:
option = input ("Please Select a Menu item.")
if (option == "0"):
break
if (option == "1"):
Item_number = input ("What is the Item Number?")
Brand_name = input ("What is the name of the Brand?")
Clothing_type = input ("What type of clothing is the Brand?")
Price = input ("How much is the item?")
brand = [Item_number, Brand_name, Clothing_type, Price]
clothing_brands.append(brand)
print ("Thank you for your input, We will begin searching to add that item into our inventory")
print (Brand_name, Clothing_type, Price)
print ("Come back in a couple of days to see if we have added the item")
if (option == "2"):
brand = input ("What is the brand you are looking for information on?")
brand = findClothing(brand)
if (brand != None):
print ("The Clothing type of this brand is:", brand[2])
if (option == "3"):
brand = input ("What is the brand you are looking for information on?")
brand = findClothing(brand)
if (brand != None):
print ("The Price of the brand is:", brand[3])
if (option == "4"):
brand = input ("What is the brand you are looking for information on?")
brand = findClothing(brand)
if (brand != None):
printBrand (brand)
else:
print ("Sorry, we do not carry this brand. If you would like for us to search for this brand, Please try option 1!")
if (option == "5"):
for brand in clothing_brands:
print (brand)
您的findClothing
方法不使用其输入参数(被循环变量覆盖),而是使用if clothing_brands in brand[1]:
没有意义的方法,因为clothing_brands
它甚至都不是字符串。
修正可修正您的错误;
def findClothing(input_brand):
found = False
for brand in clothing_brands:
if input_brand in brand[1]:
found = True
break
if found:
return brand
else:
return None
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句