From 4a8e7ce9e99a5af5fef43ab4ae15880b69831f9e Mon Sep 17 00:00:00 2001 From: Weaver <96252221+PythonRulz@users.noreply.github.com> Date: Tue, 21 Feb 2023 15:31:33 -0600 Subject: [PATCH] Create chapter_9_9.py --- chapter_9_9.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 chapter_9_9.py diff --git a/chapter_9_9.py b/chapter_9_9.py new file mode 100644 index 0000000..ff6672a --- /dev/null +++ b/chapter_9_9.py @@ -0,0 +1,22 @@ +cat_hat = {} + +# set each cat without a hat +for cat in range(1,101): + cat_hat[cat] = "off" + +# walk around that cat circle 100 times (set round 1) +rounds = 1 +while rounds <= 100: + # for each new round start at 'round' continuing to 100 adding a hat + # at each stop. For round 1 we will stop at each cat + for i in range(rounds, 101, rounds): + if cat_hat[i] == 'off': + cat_hat[i] = 'on' + else: + cat_hat[i] = 'off' + rounds += 1 +for cat in cat_hat: + if cat_hat[cat] == 'on': + print(f"Cat {cat} has a hat!") + else: + print(f"Cat {cat} has no hat!")