diff --git a/app/cafe.py b/app/cafe.py new file mode 100644 index 00000000..f5a126b4 --- /dev/null +++ b/app/cafe.py @@ -0,0 +1,28 @@ +import datetime +from app.errors import ( + VaccineError, + NotVaccinatedError, + OutdatedVaccineError, + NotWearingMaskError +) + + +class Cafe: + def __init__(self, name: str) -> None: + self.name = name + + def visit_cafe( + self, + visitor: dict + ) -> VaccineError | NotWearingMaskError | str: + + if "vaccine" not in visitor: + raise NotVaccinatedError("This visitor is no vaccinated!") + + if visitor["vaccine"]["expiration_date"] < datetime.date.today(): + raise OutdatedVaccineError("This visitor has expired vaccine!") + + if visitor["wearing_a_mask"] is False: + raise NotWearingMaskError("This visitor doesn't have a mask!") + + 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..305345f7 100644 --- a/app/main.py +++ b/app/main.py @@ -1 +1,24 @@ -# write your code here +from app.errors import ( + VaccineError, + NotWearingMaskError +) +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" + + return f"Friends can go to {cafe.name}"