Addition doesn't seem to work inside a loop

I can’t recognize the problem in my code, I try to add 4 to the index but it doesn’t work inside the loop. I tried changing the indentation but i didn’t work as well. Here is my code:

daily_sales = \
"""Edith Mcbride   ;,;$1.21   ;,;   white ;,; 
09/15/17   ,Herbert Tran   ;,;   $7.29;,; 
white&blue;,;   09/15/17 ,Paul Clarke ;,;$12.52 
;,;   white&blue ;,; 09/15/17 ,Lucille Caldwell   
;,;   $5.13   ;,; white   ;,; 09/15/17,
Eduardo George   ;,;$20.39;,; white&yellow 
;,;09/15/17   ,   Danny Mclaughlin;,;$30.82;,;   
purple ;,;09/15/17 ,Stacy Vargas;,; $1.85   ;,; 
purple&yellow ;,;09/15/17,   Shaun Brock;,; 
$17.98;,;purple&yellow ;,; 09/15/17 , 
Erick Harper ;,;$17.41;,; blue ;,; 09/15/17, 
Michelle Howell ;,;$28.59;,; blue;,;   09/15/17  7"""

#------------------------------------------------
# Start coding below!


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(";;"))

daily_transactions_clean = []
#print(daily_transactions_split)

for i in daily_transactions_split:
  for n in i:
   daily_transactions_clean.append(n.strip())


print(len(daily_transactions_clean))

customers = []
sales = []
thread_sold = []
index = 0
for index in range(len(daily_transactions_clean)):
  if (index + 3) < len(daily_transactions_clean):
    customers.append(daily_transactions_clean[index])
    sales.append(daily_transactions_clean[index+1])
    thread_sold.append(daily_transactions_clean[index+2])
    index += 4

print(sales)

Could you add a link to the lesson and perhaps some detail on what it is exactly that doesn’t work? What were you expecting to happen? Are you getting the wrong output or no output or is there an error being thrown?

https://www.codecademy.com/courses/learn-python-3/projects/thread-shed

my issue is in the 11th task

What have you tried and what did you get? You still haven’t said what’s actually wrong with your code.
Something seems a bit off about your indexing though, have you checked the output and the value of index? Is it necessary to use indexing in this case? Could you iterate through daily_transactions_clean itself?

I was trying to add 4 to index (index += 4) but the addition doesn’t work

That does work, but the next time the iteration happens, index will just one more than the previous time. If you want something permanent, try using a different named variable (not the iterator).

Thanks for answering, I’ve been stuck in this for a while. :sweat_smile:

1 Like