Hi, I am still getting number 112 as the number of “whites” in step 20 instead of 28. Can you please help?
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 trans in daily_transactions_split:
transaction_clean = []
for data in trans:
transaction_clean.append(data.replace("\n"," ").strip(" "))
transactions_clean.append(transaction_clean)
customers = []
sales = []
thread_sold = []
for transa in transactions_clean:
customers.append(transa[0])
sales.append(transa[1])
thread_sold.append(transa[2])
total_sales = 0
for sale in sales:
total_sales += float(sale.strip("$"))
thread_sold_split = []
for sale in thread_sold:
for color in sale.split("&"):
thread_sold_split.append(color)
def color_count(color):
color_total = 0
for thred_color in thread_sold_split:
if color == thred_color:
color_total += 1
return color_total
print(color_count("white"))
colors = ['red','yellow','green','white','black','blue','purple']
for color in colors:
print("Thread Shed sold {0} threads of {1} threads today.".format(color_count(color),color))
please remind me of what step 20 was? It looks like your code follows almost exactly what the video walk through had. My code was a bit different, albeit more sloppy, but it worked. It’s possible just by looking at your code that you might have a wrong indent someplace or called the wrong variable.
# Start coding below!
daily_sales_replaced = daily_sales.replace(';,;', '+')
daily_transactions = daily_sales_replaced.split(',')
#print(daily_transactions)
daily_transactions_split = []
for daily_transaction in daily_transactions:
daily_transactions_split.append(daily_transaction.split('+'))
#print(daily_transactions_split)
transactions_clean = []
for daily_transactions in daily_transactions_split:
transaction_clean = []
for transaction in daily_transactions:
transaction_clean.append(transaction.strip('\n').strip())
transactions_clean.append(transaction_clean)
#print(transactions_clean)
customers = []
sales = []
thread_sold = []
for transactions in transactions_clean:
customers.append(transactions[0])
sales.append(transactions[1])
thread_sold.append(transactions[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 color in sale.split('&'):
thread_sold_split.append(color)
#print(thread_sold_split)
def color_count(color):
color_total = 0
for color_sold in thread_sold_split:
if color == color_sold:
color_total += 1
return print(color_total)
#color_count("white")
colors = ['red','yellow','green','white','black','blue','purple']
for color in colors:
print("Thread Shed sold {0} threads of {1} thread today."
.format(color_count(color), color)
)
The output of the last loop is as follows:
24
Thread Shed sold None threads of red thread today.
34
Thread Shed sold None threads of yellow thread today.
30
Thread Shed sold None threads of green thread today.
28
Thread Shed sold None threads of white thread today.
26
Thread Shed sold None threads of black thread today.
22
Thread Shed sold None threads of blue thread today.
17
Thread Shed sold None threads of purple thread today.
Why is that? It is the same as the solution in the walk through video - or am I missing something?