Thread Shop

Hi All,

I am struggling a little bit to output the right data, but can’t seem to understand why I keep getting duplicate values at the point where I have created two empty strings in my function. Has anyone attempted the Thread Shop exercise? are you getting the same issue or is there something I am doing wrong in my code… I watched through the expert video on parts where I was stuck and I haven’t done anything different to the expert but our outputs differ.

Task:
> Blockquote

Here’s my full code…

daily_sales_replaced = daily_sales.replace(";,;", “|”)

daily_transactions = daily_sales_replaced.split(",")
#print(daily_transactions)

daily_transactions_split =
for data in daily_transactions:
daily_transactions_split.append(data.split("|"))
#print(daily_transactions_split)

transactions_clean =
for transaction in daily_transactions_split:
transaction_clean =
for data_points in transaction:
transaction_clean.append(data_points.replace("\n", “”).strip(" "))
transactions_clean.append(transaction_clean)
#print(transactions_clean)

customers =
sales =
thread_sold =

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

total_sales = 0
for sale in sales:
total_sales += float(sale.strip("$"))
#print(total_sales)

thread_sold_split =
for sale in thread_sold:
for colour in sale.split("&"):
thread_sold_split.append(colour)
#print(thread_sold_split)

def color_count(color):
count = 0
for thread_color in thread_sold_split:
if (color == thread_color):
count += 1
return count

#print(color_count(“white”))
colors = [‘red’,‘yellow’,‘green’,‘white’,‘black’,‘blue’,‘purple’]
for color in colors:
print(‘Thread Shed sold {} of {} today’.format(color_count(color), color))

Hi @sadirahkoroma ,

You may want to take a look at [How to] Format code in posts.

I’m assuming your codes should appear as follows (with indentation):

daily_sales_replaced = daily_sales.replace(";,;", "|")

daily_transactions = daily_sales_replaced.split(",")
#print(daily_transactions)

daily_transactions_split = []
for data in daily_transactions:
    daily_transactions_split.append(data.split("|"))
#print(daily_transactions_split)

transactions_clean = []
for transaction in daily_transactions_split:
    transaction_clean = []
    for data_points in transaction:
        transaction_clean.append(data_points.replace("\n", "").strip(" "))
    transactions_clean.append(transaction_clean)
#print(transactions_clean)

customers = []
sales = []
thread_sold = []

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

total_sales = 0
for sale in sales:
    total_sales += float(sale.strip("$"))
#print(total_sales)

thread_sold_split = []
for sale in thread_sold:
    for colour in sale.split("&"):
        thread_sold_split.append(colour)
#print(thread_sold_split)

def color_count(color):
    count = 0
    for thread_color in thread_sold_split:
        if (color == thread_color):
            count += 1
    return count

#print(color_count(“white”))
colors = ['red','yellow','green','white','black','blue','purple']
for color in colors:
    print('Thread Shed sold {} of {} today'.format(color_count(color), color))

I’ve previously done this exercise and when I run your code, this is the output:

Thread Shed sold 24 of red today
Thread Shed sold 34 of yellow today
Thread Shed sold 30 of green today
Thread Shed sold 28 of white today
Thread Shed sold 26 of black today
Thread Shed sold 22 of blue today
Thread Shed sold 17 of purple today

Assuming there’s no change to the exercise, the result is correct.

1 Like

Thanks for your reply! It could just be a glitch on my side.

Also, my code was formatted but when I pasted it got rid of it. Will still check out the article you suggested.

Thanks once again