python-basics-exercises icon indicating copy to clipboard operation
python-basics-exercises copied to clipboard

Alternative Solution with List (quite similar to Dictionary)

Open Fahrenberg opened this issue 4 years ago • 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]}")

Fahrenberg avatar Oct 14 '21 13:10 Fahrenberg