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 #1252

Open
wants to merge 1 commit 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.
21 changes: 21 additions & 0 deletions app/cafe.py
Original file line number Diff line number Diff line change
@@ -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()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider providing a descriptive message when raising the NotVaccinatedError to comply with the checklist requirement for descriptive error messages. Example: raise NotVaccinatedError('Visitor is not vaccinated.').


expiration_date = visitor["vaccine"]["expiration_date"]
if expiration_date < datetime.date.today():
raise OutdatedVaccineError()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider providing a descriptive message when raising the OutdatedVaccineError to comply with the checklist requirement for descriptive error messages. Example: raise OutdatedVaccineError('Visitor's vaccine is outdated.').


if not visitor.get("wearing_a_mask", False):
raise NotWearingMaskError()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider providing a descriptive message when raising the NotWearingMaskError to comply with the checklist requirement for descriptive error messages. Example: raise NotWearingMaskError('Visitor is not wearing a mask.').


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) -> 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.")
87 changes: 86 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
@@ -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))
Loading