Secure Doors
This commit is contained in:
25
securedoors.py
Normal file
25
securedoors.py
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user