Thread Shed

Hello thereI

I had a weird issue by doing the Thread Shed project in Learn Python 3 (strings module).
Since keypoint 8-9 , as printing output, each single transaction is replied 4 times and I don’t understand why (the deployment is like the walkthrough help video).
I copy my complete code below in case of help to help me.
Thanks
Fabio

#------------------------------------------------

# Start coding below!

#1 For each transaction it's reported the Name of the customer, the money paid, a color of something unclear and the date. Each pieace of data is separated by ;,; and contains useless space while each transactionand is separated by a , . 

# Start coding below!

#2

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

#print(daily_sales_replaced)

#3

daily_transactions = daily_sales_replaced.split(",")

#4

#print(daily_transactions)

#5

daily_transactions_split = []

#6

for transaction in daily_transactions:

  daily_transactions_split.append(transaction.split("+"))

#7

#print(daily_transactions_split)

#8

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)

#9

#print(transactions_clean)

# Don't know why each transaction is printed 4 times  ????????

#10

customers = []

sales = []

thread_sold = []

#11

for transaction in transactions_clean:

  customers.append(transaction[0])

  sales.append(transaction[1])

  thread_sold.append(transaction[2])

#12

#print(customers)

#print(sales)

#print(thread_sold)

#13

total_sales = 0

#14

for sale in sales:

  total_sales += float(sale.strip("$"))

#15

#print(total_sales / 4) 

# Divided by 4 because of the problem pointed out at line 137

#16

#print(thread_sold)

#17

thread_sold_split = []

#18

for sale in thread_sold:

  for color in sale.split("&"):

    thread_sold_split.append(color)

#19

def color_count(color):

  count = 0

  for i in thread_sold_split:

    if i == color:

      count += 1

  return count

#20

#print(color_count("white") / 4)

# Divided by 4 because of the problem pointed out at line 137

#21

colors = ['red','yellow','green','white','black','blue','purple']

#22

for color in colors:

  print("Thread Shed sold {0} threads of {1} thread today.".format(color_count(color)/4, color))

# Divided by 4 because of the problem pointed out at line 137

Can you please format your code using the “</>” button above? This project has loops & indentation matters in python and it’s easier to spot errors if the code is properly formatted.

# Start coding below!

#2
daily_sales_replaced = daily_sales.replace(";,;", "+")
#print(daily_sales_replaced)
#3
daily_transactions = daily_sales_replaced.split(",")
#4
#print(daily_transactions)
#5
daily_transactions_split = []
#6
for transaction in daily_transactions:
  daily_transactions_split.append(transaction.split("+"))
#7
#print(daily_transactions_split)
#8
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)
#9
#print(transactions_clean)
# Don't know why each transaction is printed 4 times  ????????

#10
customers = []
sales = []
thread_sold = []
#11
for transaction in transactions_clean:
  customers.append(transaction[0])
  sales.append(transaction[1])
  thread_sold.append(transaction[2])
#12
#print(customers)
#print(sales)
#print(thread_sold)
#13
total_sales = 0
#14
for sale in sales:
  total_sales += float(sale.strip("$"))
#15
#print(total_sales / 4) 
# Divided by 4 because of the problem pointed out at line 137

#16
#print(thread_sold)
#17
thread_sold_split = []
#18
for sale in thread_sold:
  for color in sale.split("&"):
    thread_sold_split.append(color)
#19
def color_count(color):
  count = 0
  for i in thread_sold_split:
    if i == color:
      count += 1
  return count
#20
#print(color_count("white") / 4)
# Divided by 4 because of the problem pointed out at line 137

#21
colors = ['red','yellow','green','white','black','blue','purple']
#22
for color in colors:
  print("Thread Shed sold {0} threads of {1} thread today.".format(color_count(color)/4, color))
# Divided by 4 because of the problem pointed out at line 137

I copied the code. Thank you for your help Lisa, sorry

It’s this line in Step 8. It’s indented a little too far. If you bring it back out to the same level of indentation as that second for loop that should fix the issue.
(otherwise, you’re using .append twice.)

1 Like

Yes, it worked. Lisa, many thanks :slightly_smiling_face:

1 Like