diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/app/cafe.py b/app/cafe.py new file mode 100644 index 00000000..653a1843 --- /dev/null +++ b/app/cafe.py @@ -0,0 +1,22 @@ +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("The visitor should be vaccinated.") + vaccine_expiration_date = visitor["vaccine"]["expiration_date"] + today = datetime.date.today() + if vaccine_expiration_date < today: + raise OutdatedVaccineError("Visitor's vaccine is outdated.") + if not visitor["wearing_a_mask"]: + raise NotWearingMaskError("All visitors should wear masks.") + return f"Welcome to {self.name}" diff --git a/app/errors.py b/app/errors.py new file mode 100644 index 00000000..fc10b078 --- /dev/null +++ b/app/errors.py @@ -0,0 +1,17 @@ +class VaccineError(Exception): + pass + + +class NotVaccinatedError(VaccineError): + def __init__(self, message: str) -> None: + self.message = message + + +class OutdatedVaccineError(VaccineError): + def __init__(self, message: str) -> None: + self.message = message + + +class NotWearingMaskError(Exception): + def __init__(self, message: str) -> None: + self.message = message diff --git a/app/main.py b/app/main.py index fa56336e..76ff2cd1 100644 --- a/app/main.py +++ b/app/main.py @@ -1 +1,17 @@ -# write your code here +from app.errors import NotWearingMaskError, VaccineError +from app.cafe import Cafe + + +def go_to_cafe(friends: list, 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" + else: + return f"Friends can go to {cafe.name}"