1

I am trying to get my code to give me information such as price of an item if I input the brand "Nike" or anything like that. However, I am getting the error code as the title. Please any help would be appreciated

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)

1 Answer 1

1

Your findClothing method does not use its input parameter (it's overwritten by the loop variable) and is instead using if clothing_brands in brand[1]: which makes no sense since clothing_brands is not even a string.

Fixing that fixes your error;

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.