-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
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("All friends should be vaccinated") | ||
|
||
date = visitor["vaccine"]["expiration_date"] | ||
current_date = datetime.datetime.now().date() | ||
|
||
if current_date > date: | ||
raise OutdatedVaccineError("All friends should be vaccinated") | ||
|
||
if not visitor["wearing_a_mask"]: | ||
raise NotWearingMaskError("Friends should buy") | ||
|
||
return f"Welcome to {self.name}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class VaccineError(Exception): | ||
pass | ||
|
||
|
||
class NotVaccinatedError(VaccineError): | ||
pass | ||
|
||
|
||
class OutdatedVaccineError(VaccineError): | ||
pass | ||
|
||
|
||
class NotWearingMaskError(Exception): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,22 @@ | ||
# write your code here | ||
from __future__ import annotations | ||
from app.errors import VaccineError, NotWearingMaskError | ||
from app.cafe import Cafe | ||
|
||
|
||
def go_to_cafe(friends: list, cafe: Cafe) -> str | VaccineError: | ||
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}" |