realpython/python-basics-exercises

Alternative Solution with List (quite similar to Dictionary)

Fahrenberg opened this issue · 0 comments

Quite short with two nested for loops:

cat_count = 100
cats = [False for i in range(cat_count)]



for step in range(0, cat_count):
       for selected_cat_index in range(step, cat_count,step + 1 ):
           cats[selected_cat_index] = not cats[selected_cat_index]
   

for i in range(cat_count):
    if cats[i]:
        print(f"Cat {i+1}: {cats[i]}")