From 4cd0be10d41d3daba16dcb53c2e48f6aeac2ec12 Mon Sep 17 00:00:00 2001 From: Jethro Stapelbroek Date: Tue, 18 Jul 2023 13:57:24 +0000 Subject: [PATCH] Secure Doors --- securedoors.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 securedoors.py diff --git a/securedoors.py b/securedoors.py new file mode 100644 index 0000000..cce4f79 --- /dev/null +++ b/securedoors.py @@ -0,0 +1,25 @@ +state = {} + + +def detect_anomaly(name: str, action: str) -> str: + global state + try: + if state[name] == action: + return " (ANOMALY)" + except KeyError: + if action == "exit": + return " (ANOMALY)" + return "" + + +def print_log(name: str, action: str) -> None: + paction = "entered" if action == "entry" else "exited" + print(f"{name} {paction}{detect_anomaly(name, action)}") + + +n = int(input()) + +for _ in range(n): + action, name = input().split() + print_log(name, action) + state[name] = action