STRING METHODS
link to the exercise: https://www.codecademy.com/courses/learn-python-3/projects/thread-shed
Once I got the 19th step (Define a function called **color_count**
) my code returned 1 in the console while it was supposed to return 28.
I looked at the video “get stuck” but I can’t really find any difference between my code and the script of the instructor. I will link my code below cause probably I just can’t see the error right now…
Thank you in advance for your help!!!
daily_sales_replaced=daily_sales.replace(';,;', '.')
daily_transactions=daily_sales_replaced.split(',')
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 datapoint in transaction:
transaction_clean.append(datapoint.strip())
transactions_clean.append(transaction_clean)
#print(transactions_clean)
costumers=[]
sales=[]
thread_sold=[]
for transaction in transactions_clean:
costumers.append(transaction[0])
sales.append(transaction[1])
thread_sold.append(transaction[3])
#print(costumers, sales, thread_sold)
total_sales=0
for sale in sales:
total_sales+=float(sale.strip('$'))
#print(total_sales)
#print(thread_sold)
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):
count = 0
for color_thread in thread_sold_split:
if color == color_thread:
count =+ 1
return count
print(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))