Skip to content

Commit e8e69b8

Browse files
committed
added cucumbers.py
1 parent dafb655 commit e8e69b8

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

cucumbers.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""
2+
This module contains a simple class modeling a cucumber basket.
3+
Cucumbers may be added or removed from the basket.
4+
The basket has a maximum size, however.
5+
"""
6+
7+
8+
class CucumberBasket:
9+
10+
def __init__(self, initial_count=0, max_count=10):
11+
if initial_count < 0:
12+
raise ValueError("Initial cucumber basket count must not be negative")
13+
if max_count < 0:
14+
raise ValueError("Max cucumber basket count must not be negative")
15+
16+
self._count = initial_count
17+
self._max_count = max_count
18+
19+
@property
20+
def count(self):
21+
return self._count
22+
23+
@property
24+
def full(self):
25+
return self.count == self.max_count
26+
27+
@property
28+
def empty(self):
29+
return self.count == 0
30+
31+
@property
32+
def max_count(self):
33+
return self._max_count
34+
35+
def add(self, count=1):
36+
new_count = self.count + count
37+
if new_count > self.max_count:
38+
raise ValueError("Attempted to add too many cucumbers")
39+
self._count = new_count
40+
41+
def remove(self, count=1):
42+
new_count = self.count - count
43+
if new_count < 0:
44+
raise ValueError("Attempted to remove too many cucumbers")
45+
self._count = new_count

0 commit comments

Comments
 (0)