需要帮助:TypeError:“在<string>中”需要将字符串作为左操作数,而不是列表

克里斯托弗·李

如果我输入品牌“ 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)
约阿希姆·伊萨克森(Joachim Isaksson)

您的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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

需要帮助:TypeError:“在<string>中”需要将字符串作为左操作数,而不是列表

来自分类Dev

TypeError:'in <string>'需要将字符串作为左操作数,而不是列表

来自分类Dev

在<string>'中需要将字符串作为左操作数,而不是元组

来自分类Dev

TypeError:'in <string>'需要将字符串作为左操作数,而不是int

来自分类Dev

发生异常:TypeError'in <string>'需要将字符串作为左操作数,而不是Series

来自分类Dev

TypeError:'in <string>'需要将字符串作为左操作数,而不是ObjectListView wxPython的int

来自分类Dev

TypeError:'in <string>'需要将字符串作为左操作数,而不是元组

来自分类Dev

TypeError:'in <string>'需要将字符串作为左操作数,而不是QueryDict

来自分类Dev

如何处理此TypeError:'in <string>'需要将字符串作为左操作数,而不是元组

来自分类Dev

我在<string>中获取'需要字符串作为左操作数,而不是元组

来自分类Dev

为什么会出现TypeError:'in <string>'需要将字符串作为左操作数,而不是在运行程序时列出错误?

来自分类Dev

类型错误:'in <string>' 需要字符串作为左操作数,而不是方法 PYTHON

来自分类Dev

遍历字典并获取TypeError:'in <string>'要求将字符串作为左操作数,而不是列表

来自分类Dev

TypeError:'in <字符串>'需要字符串作为左操作数而不是列表

来自分类Dev

如何解决错误:“在字符串中”需要字符串作为左操作数而不是元组?

来自分类Dev

为什么键入错误:<string>中的字符串要求字符串作为左操作数,而不是列表

来自分类Dev

不区分大小写,并且输入age为31时显示错误:TypeError:'in <string>'需要将string作为左操作数

来自分类Dev

逐步完成指向字符串的指针数组-“需要左值作为增量操作数”

来自分类Dev

Python / Jython:如果字符串中的子字符串总是导致TypeError:字符串成员测试需要char左操作数

来自分类Dev

需要左值作为赋值c的左操作数

来自分类Dev

需要左值作为赋值的左操作数

来自分类Dev

C ++帮助:错误:需要左值作为增量操作数

来自分类Dev

错误:在与指针的交换中,需要左值作为赋值的左操作数

来自分类Dev

错误:在与指针的交换中,需要左值作为赋值的左操作数

来自分类Dev

jQuery TypeError:“ msgs”为空,需要帮助

来自分类Dev

C中的“需要左值作为增量操作数”错误

来自分类Dev

需要LVALUE作为C程序中赋值的左操作数

来自分类Dev

左值需要作为 C 程序中的一元“&”操作数

来自分类Dev

错误:需要左值作为赋值的左操作数(C)

Related 相关文章

  1. 1

    需要帮助:TypeError:“在<string>中”需要将字符串作为左操作数,而不是列表

  2. 2

    TypeError:'in <string>'需要将字符串作为左操作数,而不是列表

  3. 3

    在<string>'中需要将字符串作为左操作数,而不是元组

  4. 4

    TypeError:'in <string>'需要将字符串作为左操作数,而不是int

  5. 5

    发生异常:TypeError'in <string>'需要将字符串作为左操作数,而不是Series

  6. 6

    TypeError:'in <string>'需要将字符串作为左操作数,而不是ObjectListView wxPython的int

  7. 7

    TypeError:'in <string>'需要将字符串作为左操作数,而不是元组

  8. 8

    TypeError:'in <string>'需要将字符串作为左操作数,而不是QueryDict

  9. 9

    如何处理此TypeError:'in <string>'需要将字符串作为左操作数,而不是元组

  10. 10

    我在<string>中获取'需要字符串作为左操作数,而不是元组

  11. 11

    为什么会出现TypeError:'in <string>'需要将字符串作为左操作数,而不是在运行程序时列出错误?

  12. 12

    类型错误:'in <string>' 需要字符串作为左操作数,而不是方法 PYTHON

  13. 13

    遍历字典并获取TypeError:'in <string>'要求将字符串作为左操作数,而不是列表

  14. 14

    TypeError:'in <字符串>'需要字符串作为左操作数而不是列表

  15. 15

    如何解决错误:“在字符串中”需要字符串作为左操作数而不是元组?

  16. 16

    为什么键入错误:<string>中的字符串要求字符串作为左操作数,而不是列表

  17. 17

    不区分大小写,并且输入age为31时显示错误:TypeError:'in <string>'需要将string作为左操作数

  18. 18

    逐步完成指向字符串的指针数组-“需要左值作为增量操作数”

  19. 19

    Python / Jython:如果字符串中的子字符串总是导致TypeError:字符串成员测试需要char左操作数

  20. 20

    需要左值作为赋值c的左操作数

  21. 21

    需要左值作为赋值的左操作数

  22. 22

    C ++帮助:错误:需要左值作为增量操作数

  23. 23

    错误:在与指针的交换中,需要左值作为赋值的左操作数

  24. 24

    错误:在与指针的交换中,需要左值作为赋值的左操作数

  25. 25

    jQuery TypeError:“ msgs”为空,需要帮助

  26. 26

    C中的“需要左值作为增量操作数”错误

  27. 27

    需要LVALUE作为C程序中赋值的左操作数

  28. 28

    左值需要作为 C 程序中的一元“&”操作数

  29. 29

    错误:需要左值作为赋值的左操作数(C)

热门标签

归档