From dab13a380b8e28e30af65e4f169c1308b60c3ff4 Mon Sep 17 00:00:00 2001 From: sandeepdharembra Date: Sat, 1 Jan 2022 18:19:33 +0530 Subject: [PATCH] Alternate Solution --- .../9a-challenge-cats-with-hats.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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') pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy