Skip to content

Commit

Permalink
solution2
Browse files Browse the repository at this point in the history
  • Loading branch information
Ihor-MA committed Aug 24, 2023
1 parent 5cba82e commit 4ec3cb2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/cafe.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime

from app.errors import (
NotVaccinatedError,
OutdatedVaccineError,
Expand Down
19 changes: 12 additions & 7 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@
from app.cafe import Cafe


def go_to_cafe(friends: list, cafe: Cafe) -> str | VaccineError:
masks_to_buy = 0
def get_amount_without_mask(friends: list) -> int:
return len([friend for friend in friends if not friend["wearing_a_mask"]])

for friend in friends:

def go_to_cafe(friends: list, cafe: Cafe) -> str:

for i, friend in enumerate(friends):
try:
cafe.visit_cafe(friend)
if i == len(friends) - 1 and get_amount_without_mask(friends) != 0:
return (f"Friends should buy "
f"{get_amount_without_mask(friends)} masks")

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"
if i == len(friends) - 1 and get_amount_without_mask(friends) != 0:
return (f"Friends should buy "
f"{get_amount_without_mask(friends)} masks")

return f"Friends can go to {cafe.name}"

0 comments on commit 4ec3cb2

Please sign in to comment.