Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lockdown cafe task solution #1207

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added app/__init__.py
Empty file.
22 changes: 22 additions & 0 deletions app/cafe.py
Original file line number Diff line number Diff line change
@@ -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}"
17 changes: 17 additions & 0 deletions app/errors.py
Original file line number Diff line number Diff line change
@@ -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
18 changes: 17 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
@@ -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}"
Loading