diff --git a/app/cafe.py b/app/cafe.py new file mode 100644 index 00000000..07d44e3a --- /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: + current_date = datetime.date.today() + if "vaccine" not in visitor: + raise NotVaccinatedError("Visitor is not vaccinated") + if visitor["vaccine"]["expiration_date"] < current_date: + raise OutdatedVaccineError("Date of vaccination is expired") + if visitor["wearing_a_mask"] is False: + raise NotWearingMaskError("Visitor should Wear 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..e576eb2b 100644 --- a/app/main.py +++ b/app/main.py @@ -1 +1,25 @@ -# write your code here +from app.cafe import Cafe +from app.errors import ( + NotWearingMaskError, + OutdatedVaccineError, + NotVaccinatedError +) + + +def go_to_cafe(friends: list, cafe: Cafe) -> str: + count_friends = 0 + dont_vaccinated = 0 + for friend in friends: + try: + cafe.visit_cafe(friend) + except (OutdatedVaccineError, NotVaccinatedError): + dont_vaccinated += 1 + except NotWearingMaskError: + count_friends += 1 + + if dont_vaccinated > 0: + return "All friends should be vaccinated" + if count_friends > 0: + return f"Friends should buy {count_friends} masks" + + return f"Friends can go to {cafe.name}"