diff --git a/app/cafe.py b/app/cafe.py new file mode 100644 index 00000000..f9e8c4a2 --- /dev/null +++ b/app/cafe.py @@ -0,0 +1,18 @@ +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("You have to be vaccinated.") + elif visitor["vaccine"].get("expiration_date") < datetime.date.today(): + raise OutdatedVaccineError("Your vaccine is expired.") + elif not visitor.get("wearing_a_mask"): + raise NotWearingMaskError("You have to be in 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..d984f752 100644 --- a/app/main.py +++ b/app/main.py @@ -1 +1,16 @@ -# 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 NotWearingMaskError: + masks_to_buy += 1 + except VaccineError: + return "All friends should be vaccinated" + if masks_to_buy: + return f"Friends should buy {masks_to_buy} masks" + return f"Friends can go to {cafe.name}"