From 5cba82e159060e3ff2afb0d871edecbe7dc46c67 Mon Sep 17 00:00:00 2001 From: Igor Berezivskyi Date: Tue, 22 Aug 2023 14:49:52 +0300 Subject: [PATCH] Solution --- app/cafe.py | 26 ++++++++++++++++++++++++++ app/errors.py | 14 ++++++++++++++ app/main.py | 23 ++++++++++++++++++++++- 3 files changed, 62 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..351e1d60 --- /dev/null +++ b/app/cafe.py @@ -0,0 +1,26 @@ +import datetime +from app.errors import ( + NotVaccinatedError, + OutdatedVaccineError, + NotWearingMaskError +) + + +class Cafe: + def __init__(self, name: str) -> None: + self.name = name + + def visit_cafe(self, visitor: dict) -> str: + if "vaccine" not in visitor: + raise NotVaccinatedError("All friends should be vaccinated") + + date = visitor["vaccine"]["expiration_date"] + current_date = datetime.datetime.now().date() + + if current_date > date: + raise OutdatedVaccineError("All friends should be vaccinated") + + if not visitor["wearing_a_mask"]: + raise NotWearingMaskError("Friends should buy") + + return f"Welcome to {self.name}" diff --git a/app/errors.py b/app/errors.py new file mode 100644 index 00000000..fb16164d --- /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..3d171dbd 100644 --- a/app/main.py +++ b/app/main.py @@ -1 +1,22 @@ -# write your code here +from __future__ import annotations +from app.errors import VaccineError, NotWearingMaskError +from app.cafe import Cafe + + +def go_to_cafe(friends: list, cafe: Cafe) -> str | VaccineError: + 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}"