Right…
Here’s what I think your code was supposed to look like. I’ve commented out the print
of the raw sales data, because I don’t need it, and I’ve added a few additional print
statements of my own to make the output clearer. Also, re-indented it 
Edit: Ignore the from sales_data import daily_sales
line… I saved the raw data to another file, for convenience, and imported it so I could select all for copy & pasting to here…
from sales_data import daily_sales
daily_sales_replaced = daily_sales.replace(';,;', '+')
daily_transactions = daily_sales_replaced.split(',')
#print(daily_transactions)
daily_transactions_split = []
for transaction in daily_transactions:
daily_transactions_split.append(transaction.split('+'))
#print(daily_transactions_split)
transactions_clean = []
for transaction in daily_transactions_split:
transaction_clean = []
for data_point in transaction:
transaction_clean.append(data_point.replace('\n', '').strip(' '))
transactions_clean.append(transaction_clean)
#print(transactions_clean)
customers = []
sales = []
thread_sold = []
for transaction in transactions_clean:
customers.append(transaction[0])
sales.append(transaction[1])
thread_sold.append(transaction[2])
#print(customers)
#print(sales)
#print(thread_sold)
total_sales = 0
for sale in sales:
total_sales += float(sale.strip('$'))
print("\nPrinting total_sales...\n") # added to make output clearer
print(total_sales)
print("\nPrinting thread_sold\n") # added to make output clearer
print(thread_sold)
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 thread_color in thread_sold_split:
if color == thread_color:
color_total += 1
return color_total
print("\nPrinting color_count('white')...\n") # added to make output clearer
print(color_count('white')) # :face_with_monocle: HERE IS THE PROBLEM LINE!!! The output gives me 112, which also affects my last two line's the string formatting numbers, too
print("^ is your problem ??\n\n")
colors = ['red','yellow','green','white','black','blue','purple']
for color in colors:
print('Thread Shed sold {} threads in {} today.'.format(color_count(color), color))
When I run the code…
Python 3.6.1 (default, Dec 2015, 13:05:11)
[GCC 4.8.2] on linux
Printing total_sales...
1498.7400000000005
Printing thread_sold
['white', 'white&blue', 'white&blue', 'white', 'white&yellow', 'purple', 'purple&yellow', 'purple&yellow', 'blue', 'blue', 'purple&blue', 'white', 'white&red', 'white&blue&red', 'blue','green&blue', 'green&blue&red', 'green&blue&red', 'black', 'black&yellow', 'white&black&yellow', 'white&black&yellow', 'green', 'green&yellow', 'green&yellow&blue', 'green&yellow&purple&blue', 'black', 'black&blue', 'black&blue', 'black', 'black&purple', 'black&purple', 'yellow', 'yellow&red', 'yellow', 'yellow&blue', 'yellow&blue&red', 'black', 'black&red', 'black&red', 'white&black&red', 'yellow', 'yellow&black', 'green&yellow&black', 'yellow', 'white&yellow', 'white&yellow&black', 'yellow', 'yellow', 'white', 'white&black', 'white&black', 'white&black&red', 'purple', 'purple&yellow', 'purple&yellow', 'green&purple&yellow', 'red', 'yellow&red', 'green&yellow&red', 'red', 'green&red', 'green&white&red', 'white', 'white&red', 'purple', 'purple', 'green', 'green', 'green', 'red', 'white&red', 'white&purple&red', 'red', 'black&red', 'black&red', 'black&red', 'green', 'green&yellow', 'green&yellow&blue', 'purple', 'purple&black', 'yellow', 'yellow', 'yellow&blue', 'green', 'green', 'white', 'white&blue', 'white&black&blue', 'green', 'green&yellow', 'green&yellow&black', 'green', 'green', 'green&purple', 'green', 'green&white', 'green&white&blue', 'green&white&blue']
Printing color_count('white')...
28
^ is your problem ??
Thread Shed sold 24 threads in red today.
Thread Shed sold 34 threads in yellow today.
Thread Shed sold 30 threads in green today.
Thread Shed sold 28 threads in white today.
Thread Shed sold 26 threads in black today.
Thread Shed sold 22 threads in blue today.
Thread Shed sold 17 threads in purple today.
As you can see, I get 28… which is what you were expecting?
All I can assume is that I’ve fixed something that was broken, but I can’t see what was broken as I’ve not changed anything except add a few print
calls…