From 19e0bbb809c74d2d1f706cf3f790ff7fedc22b4c Mon Sep 17 00:00:00 2001 From: H1kki Date: Fri, 28 Jul 2023 13:35:47 +0300 Subject: [PATCH 1/3] solution --- app/cafe.py | 25 +++++++++++++++++++++++++ app/errors.py | 14 ++++++++++++++ app/main.py | 17 ++++++++++++++++- 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 app/cafe.py create mode 100644 app/errors.py diff --git a/app/cafe.py b/app/cafe.py new file mode 100644 index 00000000..144e47bc --- /dev/null +++ b/app/cafe.py @@ -0,0 +1,25 @@ +from __future__ import annotations +import datetime +from app.errors import ( + NotVaccinatedError, + NotWearingMaskError, + OutdatedVaccineError +) + + +class Cafe: + def __init__(self, name: str) -> None: + self.name = name + + def visit_cafe(self, visitor: dict) -> str | Exception: + if "vaccine" not in visitor: + raise NotVaccinatedError("Not vaccinated!") + + expiration_date = visitor["vaccine"].get("expiration_date") + if expiration_date and expiration_date < datetime.date.today(): + raise OutdatedVaccineError("Outdated vaccine!") + + if "wearing_a_mask" in visitor and not visitor["wearing_a_mask"]: + raise NotWearingMaskError("Not wearing a mask!") + + return f"Welcome to {self.name}" diff --git a/app/errors.py b/app/errors.py new file mode 100644 index 00000000..dbc06145 --- /dev/null +++ b/app/errors.py @@ -0,0 +1,14 @@ +class VaccineError(Exception): + pass + + +class NotVaccinatedError(VaccineError): + pass + + +class OutdatedVaccineError(VaccineError): + pass + + +class NotWearingMaskError(Exception): + pass diff --git a/app/main.py b/app/main.py index fa56336e..e1215e8e 100644 --- a/app/main.py +++ b/app/main.py @@ -1 +1,16 @@ -# write your code here +from app.errors import NotWearingMaskError, VaccineError +from app.cafe import Cafe + + +def go_to_cafe(friends: list[dict], cafe: Cafe) -> str: + masks_to_buy = 0 + for friend in friends: + try: + cafe.visit_cafe(friend) + except VaccineError: + return "All friends should be vaccinated" + except NotWearingMaskError: + masks_to_buy += 1 + if masks_to_buy > 0: + return f"Friends should buy {masks_to_buy} masks" + return f"Friends can go to {cafe.name}" From 12a02a5052d80284d34daf286fbeb5752753e88b Mon Sep 17 00:00:00 2001 From: H1kki Date: Wed, 16 Aug 2023 20:24:00 +0300 Subject: [PATCH 2/3] solution --- app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index e1215e8e..337465b5 100644 --- a/app/main.py +++ b/app/main.py @@ -13,4 +13,4 @@ def go_to_cafe(friends: list[dict], cafe: Cafe) -> str: masks_to_buy += 1 if masks_to_buy > 0: return f"Friends should buy {masks_to_buy} masks" - return f"Friends can go to {cafe.name}" + return f"Friends can go to {cafe.name} " From 35583f48ca43a9d11d0f861f8eb513dce8e599e3 Mon Sep 17 00:00:00 2001 From: H1kki Date: Wed, 16 Aug 2023 20:24:39 +0300 Subject: [PATCH 3/3] solution --- app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index 337465b5..e1215e8e 100644 --- a/app/main.py +++ b/app/main.py @@ -13,4 +13,4 @@ def go_to_cafe(friends: list[dict], cafe: Cafe) -> str: masks_to_buy += 1 if masks_to_buy > 0: return f"Friends should buy {masks_to_buy} masks" - return f"Friends can go to {cafe.name} " + return f"Friends can go to {cafe.name}"