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..5654a458 --- /dev/null +++ b/app/cafe.py @@ -0,0 +1,21 @@ +import datetime +from app.errors import (NotVaccinatedError, NotWearingMaskError, + OutdatedVaccineError) + + +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() + + expiration_date = visitor["vaccine"]["expiration_date"] + if expiration_date < datetime.date.today(): + raise OutdatedVaccineError() + + if not visitor.get("wearing_a_mask", False): + raise NotWearingMaskError() + + return f"Welcome to {self.name}" diff --git a/app/errors.py b/app/errors.py new file mode 100644 index 00000000..6f60eeac --- /dev/null +++ b/app/errors.py @@ -0,0 +1,17 @@ +class VaccineError(Exception): + pass + + +class NotVaccinatedError(VaccineError): + def __init__(self) -> None: + super().__init__("Visitor is not vaccinated.") + + +class OutdatedVaccineError(VaccineError): + def __init__(self) -> None: + super().__init__("Visitor's vaccine is outdated.") + + +class NotWearingMaskError(Exception): + def __init__(self) -> None: + super().__init__("Visitor is not wearing a mask.") diff --git a/app/main.py b/app/main.py index fa56336e..b82deb70 100644 --- a/app/main.py +++ b/app/main.py @@ -1 +1,86 @@ -# write your code here +from app.cafe import Cafe +import datetime + + +def go_to_cafe(friends: list[dict], cafe: Cafe) -> str: + masks_needed = 0 + all_vaccinated = True + + for friend in friends: + if "vaccine" not in friend: + all_vaccinated = False + continue + + expiration_date = friend["vaccine"]["expiration_date"] + if expiration_date < datetime.date.today(): + all_vaccinated = False + + if not friend.get("wearing_a_mask", False): + masks_needed += 1 + + if not all_vaccinated: + return "All friends should be vaccinated" + + if masks_needed > 0: + return f"Friends should buy {masks_needed} masks" + + return f"Friends can go to {cafe.name}" + + +# Example usage +if __name__ == "__main__": + kfc = Cafe("KFC") + + friends = [ + { + "name": "Alisa", + "vaccine": { + "expiration_date": datetime.date.today() + }, + "wearing_a_mask": True + }, + { + "name": "Bob", + "vaccine": { + "expiration_date": datetime.date.today() + }, + "wearing_a_mask": True + }, + ] + + print(go_to_cafe(friends, kfc)) + + friends = [ + { + "name": "Alisa", + "vaccine": { + "expiration_date": datetime.date.today() + }, + "wearing_a_mask": False + }, + { + "name": "Bob", + "vaccine": { + "expiration_date": datetime.date.today() + }, + "wearing_a_mask": False + }, + ] + + print(go_to_cafe(friends, kfc)) + + friends = [ + { + "name": "Alisa", + "wearing_a_mask": True + }, + { + "name": "Bob", + "vaccine": { + "expiration_date": datetime.date.today() + }, + "wearing_a_mask": True + }, + ] + + print(go_to_cafe(friends, kfc))