Thread Shed Python 3 (Step 22)

Hi everyone,

I’m stuck on the last step of https://www.codecademy.com/courses/learn-python-3/projects/thread-shed and don’t understand why my code doesn’t work.

The given solution is this:

for i in colors:
print(“Thread Shed sold {} threads of {} thread today”.format(color_count(i),i))

But I tried this, and the code doesn’t iterate through the other colours in the list (instead just printing the number of purple threads only):

for i in colors:
output = “Thread Shed sold {} threads of {} thread today”.format(color_count(i),i)
print (output)

Here is the rest of my code, FYI:

daily_sales_replaced = daily_sales.replace(’;,;’,’;’)
daily_transactions = daily_sales_replaced.split(",")
daily_transactions_split =

for i in daily_transactions:
daily_transactions_split.append(i.split(’;’))

transactions_clean =
for i in daily_transactions_split:
transaction_clean =
for item in i:
transaction_clean.append(item.replace("\n","").strip())
transactions_clean.append(transaction_clean)
#print(transactions_clean)

customers =
sales =
thread_sold =

for i in transactions_clean:
customers.append(i[0])
sales.append(i[1])
thread_sold.append(i[2])
#print(customers,sales,thread_sold)

total_sales = float(0)
for i in sales:
a = i.strip(’$’)
total_sales += float(a)
#print(total_sales)

#print(thread_sold)

thread_sold_split =
for i in thread_sold:
if “&” not in i:
thread_sold_split.append(i)
else:
b = i.split(’&’)
for i in b:
thread_sold_split.append(i)
#print(thread_sold_split)

def color_count(colour):
counter = 0
for i in thread_sold_split:
if i == colour:
counter += 1
return counter

print(color_count(‘green’))

colors = [‘red’,‘yellow’,‘green’,‘white’,‘black’,‘blue’,‘purple’]

Thanks in advance!

It’s hard to say as your pasted code appears to be missing its indentation. Indentation is essential to Python as its how code blocks are grouped together. A single output suggests that for loop isn’t actually looping at all.

Indentation for a standard loop should be similar to the following-

for x in [1, 2, 3]:
    print(x)
2 Likes

Thanks for pointing it out - I just missed the indentation!