diff --git a/app/cafe.py b/app/cafe.py new file mode 100644 index 00000000..8d1e8aec --- /dev/null +++ b/app/cafe.py @@ -0,0 +1,23 @@ +from datetime import date +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: + vaccine = visitor.get("vaccine") + if vaccine is None: + raise NotVaccinatedError("Visitor should have vaccine") + current_date = date.today() + exp_date = vaccine["expiration_date"] + if exp_date < current_date: + raise OutdatedVaccineError("Visitor has expired vaccine") + if not visitor["wearing_a_mask"]: + raise NotWearingMaskError("Visitor isn't wearing 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..26e9b9ff 100644 --- a/app/main.py +++ b/app/main.py @@ -1 +1,21 @@ -# write your code here +from app.cafe import Cafe +from app.errors import ( + VaccineError, + NotWearingMaskError +) + + +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: + return f"Friends should buy {masks_to_buy} masks" + + return f"Friends can go to {cafe.name}"