Error: AttributeError: 'str' object has no attribute 'sort'

brand_name = "Huawei"
count = 3
 while count <= 3:
    brands = str(input(" Enter cellphone brandname:"))
    brand_name.insert(brands, count)
    count = 1 + count
brand_name.sort()
brand_name.remove("Huawei")
print(brand_name)

I suspect what you want to do is sort a list of brands. In that case you have to start with a list like

brands = []

Then you can .append more brands to the list as entered. After you are done you can sort the list by

brands.sort()

This will sort brands in place. If you want to maintain the original list then you will have to make a copy and sort it. You can do it as follows (depending on your version of Python)

sorted = brands.copy()
sorted.sort()

or

(sorted := brands.copy()).sort()
commented: it works thank you +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.