Question on final step for Thread Shed project


#1

Hello!

I hope I’m posting this in the right area.

I have a question regarding Step 22 in the ‘Thread Shed’ project. I am able to print out the count of each color using .format(), but it prints everything for each color, leading to a lot of text in the console.

Can someone point me in the right direction for just printing each color once?

I’ve tried setting count variables, if statements, nested for loops…They all come out the same.

Here is my current code for this step:

for color in thread_sold_split:
  if color in colors:
    print("Thread Shed sold {} threads of {} thread today.".format(color_count(color), color))

Strings and Console Output


#2

Nevermind! I managed to figure it out after all…while loops are very handy indeed :grin:

Here is the code I used in case anyone needs a push in the right direction:

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

counter = 0

while counter < len(colors):
  for color in colors:
    if color in colors:
      print("Thread Shed sold {} threads of {} thread today.".format(color_count(color), color))
    counter += 1

#3

for -> while … doesn’t make a difference.
You changed something else as well

(And that if-statement doesn’t do anything, because colors is where you got it from)


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.