diff --git a/ch09-lists-tuples-and-dictionaries/9a-challenge-cats-with-hats.py b/ch09-lists-tuples-and-dictionaries/9a-challenge-cats-with-hats.py index 3e081c0..541294b 100644 --- a/ch09-lists-tuples-and-dictionaries/9a-challenge-cats-with-hats.py +++ b/ch09-lists-tuples-and-dictionaries/9a-challenge-cats-with-hats.py @@ -19,3 +19,20 @@ def get_cats_with_hats(array_of_cats): cats = [False] * (100 + 1) print(get_cats_with_hats(cats)) + +## Alternate Solution + +cats = {} + +for i in range(1, 101): + cats[i] = False + +for i in range(1, 101): + for j in range(i,101,i): + cats[j] = not cats[j] + +print("Cats having hats") + +for i in cats: + if cats[i]: + print(f'Cat # {i} has a hat on')