-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsurfshop.py
More file actions
39 lines (29 loc) · 1.15 KB
/
surfshop.py
File metadata and controls
39 lines (29 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from datetime import datetime
from typing import Optional
MAX_SURFBOARDS = 4
class TooManyBoardsError(Exception):
# pass
def __str__(self) -> str:
return f'Cart cannot have more than {MAX_SURFBOARDS} surfboards in it!'
class CheckoutDateError(Exception):
# pass
def __str__(self) -> str:
return 'Checkout date must be in the future.'
class ShoppingCart:
def __init__(self) -> None:
self.num_surfboards: int = 0
self.checkout_date: Optional[datetime] = None
self.locals_discount: bool = False
def add_surfboards(self, quantity: int=1) -> str:
if self.num_surfboards + quantity > MAX_SURFBOARDS:
raise TooManyBoardsError()
self.num_surfboards += quantity
suffix = '' if quantity == 1 else 's'
return f'Successfully added {quantity} surfboard{suffix} to cart!'
def set_checkout_date(self, date: datetime) -> None:
if date <= datetime.now():
raise CheckoutDateError()
self.checkout_date = date
def apply_locals_discount(self):
# pass # gives failure as doesn't set locals discount to true
self.locals_discount = True