I am currently completing the Thread Shed task. My code is nearly identical to the walkthrough but my numbers for total_sales and colour_count(“white”) are coming back wrong. I really don’t understand where I have messed up!
#Break up ‘daily_sales’ in easy to understand lists
daily_sales_replaced = daily_sales.replace(“;,;”, “;”)
#print(daily_sales_replaced)
daily_transactions = daily_sales_replaced.split(“,”)
#print(daily_transactions)
daily_transactions_split =
for transactions in daily_transactions:
daily_transactions_split.append(transactions.split(‘;’))
#print(daily_transactions_split)
transactions_clean =
for transactions in daily_transactions_split:
transaction_clean =
for i in transactions:
transaction_clean.append(i.replace(“\n”, “”) .strip(" "))
transactions_clean.append(transaction_clean)
#print(transactions_clean)
customers =
sales =
thread_sold =
for values in transactions_clean:
customers.append(values[0])
sales.append(values[1])
thread_sold.append(values[2])
#print(customers)
#print(sales)
#print(thread_sold)
#Determine the total value of daily sales
total_sales = 0
for value in sales:
total_sales += float(value.strip(“$”))
#print(total_sales)
#should be 1498.7400000000005!
#How much thread of any specific colour was sold?
thread_sold_split =
for thread in thread_sold:
for colour in thread.split(“&”):
thread_sold_split.append(colour)
#print(thread_sold_split)
def colour_count(colour):
count = 0
for threads in thread_sold_split:
if colour == threads:
count += 1
return count
#print(colour_count(“white”))
#should be 28!
colours = [“red”, “yellow”, “green”, “white”, “black”, “blue”, “purple”]
for colour in colours:
print(“{} {} thread were sold by Thread Shed.”.format(colour_count(colour), colour))